From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA08585; Fri, 6 Feb 2004 19:57:52 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA09386 for ; Fri, 6 Feb 2004 19:57:51 +0100 (MET) Received: from alex.baretta.com ([217.220.212.238]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i16Ivov17716 for ; Fri, 6 Feb 2004 19:57:50 +0100 (MET) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by alex.baretta.com (8.12.8/8.12.8) with ESMTP id i16Iw5aI022488; Fri, 6 Feb 2004 19:58:06 +0100 Message-ID: <4023E3BD.8040907@baretta.com> Date: Fri, 06 Feb 2004 19:58:05 +0100 From: Alex Baretta User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 To: brogoff@speakeasy.net, Ocaml Subject: Re: [Caml-list] What about polymorphic union types in functors? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; baretta:01 baretta:01 caml-list:01 functors:01 brogoff:01 gcaml:01 gcaml:01 typecheck:01 runtime:01 morphism:01 statically:01 model:01 compiler:01 compiler:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk brogoff@speakeasy.net wrote: > On Fri, 6 Feb 2004, Alex Baretta wrote: > Looks like you are implementing GCaml style polymorphism by hand. Last I read, > work on GCaml was slated to resume after 3.07. The original system looked > quite promising, but I have no idea how it will interact with the module system, > and all of the other non corish extensions (OO, polymorphic variants, etc) > that make up the full language. > > -- Brian Well, I like the GCaml approach, but I think that what I need is actually simpler than function overloading. I actually need variant types, for each variant identifies a specific object, which is meaningful in specific context (read, set). The variant types I use are polymorphic because the union of two such types is meaningful in an enlarged context (set union). I need the ocaml compiler to typecheck the use of variant tags to ensure that no tag is used in a context where it is not meaningful. The absence of such static typechecking would force me to throw an exception at runtime if a tag is used where it is not meaningful. Such typechecking is possible, and I actually rely heavily on it. What I need is a _union_ morphism between a pair of similar modules and a third module similar to the first two. From an algebraic stadpoint, this operator is well defined. However, ocaml is unable to compile such code because pattern matching on polymorphic variants requires all variants to be known statically. However, I suspect that this limitation is due to the implementation rather than the underlying model. If the compiler knew that F1.t and F2.t were polymorphic variant types, then it could dispatch be executing sequentially the pattern matching code for F1.t defined by the F1 module and the pattern matching code for F2.t defined in the F2 module. This can be done because at the time when F1 and F2 are compiled all polymorphic variants are actually known. There might be some corner cases to be worked out, but the general principle ought to work. Alex ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners