From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0685ABBBB for ; Sun, 3 Sep 2006 11:09:19 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k8399GbO025613 for ; Sun, 3 Sep 2006 11:09:18 +0200 Received: from localhost (moose-172 [172.16.254.3]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id k839939B016601; Sun, 3 Sep 2006 18:09:03 +0900 (JST) Date: Sun, 03 Sep 2006 18:08:56 +0900 (JST) Message-Id: <20060903.180856.123164161.garrigue@math.nagoya-u.ac.jp> To: avaron@gmail.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Polymorphic variants question From: Jacques Garrigue In-Reply-To: References: <7E1CAC5D-67CC-4A5C-8DE6-BB2A60A6615B@gmail.com> <20060902.201646.110439764.garrigue@math.nagoya-u.ac.jp> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44FA9BBC.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; variants:01 variants:01 struct:01 struct:01 functor:01 functor:01 unions:01 2006:98 2006,:98 wrote:01 polymorphic:01 polymorphic:01 abstract:01 signatures:01 caml-list:01 From: Andres Varon Subject: Re: [Caml-list] Polymorphic variants question Date: Sat, 2 Sep 2006 21:22:55 -0400 > > On Sep 2, 2006, at 7:16 AM, Jacques Garrigue wrote: > > > Just that the concrete type is much simpler. > > The abstract type does not work directly, as you need a way to ensure > > that B.t and C.t are compatible. Otherwise, one could write > > > > module D = A(struct type t = [ `A of int] ... end) > > (struct type t = [ `A of string] ... end) > > > > which is clearly incorrect. > > I use a more restricted version of polymorphic variants to ensure > that two functions that are being composed through a match in the > style of the question do not share a tag (and so one function will > not override the expected behavior of the second one), even if the > tags are fully compatible; being this the case, your example cannot > occur. > > I am not an expert in programming languages, and I cannot see - in > this restricted case - a reason why that functor could still be > problematic. Is there some? Just that I don't see how you could possibly enforce the above condition either, without something in the signatures to tell the system that argument sets of B.t and C.t must be disjoint. Or you are telling me that, as you already included "type t = [B.t | C.t]" in the return type of the functor, there is already an implicit constraint on B.t and C.t. This is right indeed, but the point is that you need some logic to handle this constraint; and you want also to be able to create unions without necessarily writing it in the outside signature. Jacques Garrigue