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=1.5 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 11ECDBC6B for ; Wed, 25 Oct 2006 08:03:17 +0200 (CEST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.239]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9P63GaJ027434 for ; Wed, 25 Oct 2006 08:03:16 +0200 Received: by wx-out-0506.google.com with SMTP id s6so44299wxc for ; Tue, 24 Oct 2006 23:03:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=dGTxj2PygvY4humSLvTuYQkd9TYO78PN/rsiynjtKjGaDfg6VPRXkAvDSeRIOkxVf1/Um3k9KKqHdmdXnZOjLX9D9kcf/Ra6HZnLQxP0VOqp1+KNH/ShXA1x6vHqRfaTaq3GJSz2PeJMkiz3Hb4WiAu8YNXDdOcQkjkPaEFPSCQ= Received: by 10.70.47.19 with SMTP id u19mr346050wxu; Tue, 24 Oct 2006 23:03:15 -0700 (PDT) Received: by 10.70.40.12 with HTTP; Tue, 24 Oct 2006 23:03:15 -0700 (PDT) Message-ID: <9d3ec8300610242303q44cf7ec1pec711f530616f16a@mail.gmail.com> Date: Wed, 25 Oct 2006 08:03:15 +0200 From: "Till Varoquaux" To: "Jacques Garrigue" Subject: Re: [Caml-list] Simple(?) subtyping problem... Cc: caml-list@yquem.inria.fr In-Reply-To: <20061025.074628.104028766.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <9d3ec8300610241345k1600fd9dqe3a3bba5c4bd9def@mail.gmail.com> <20061025.074628.104028766.garrigue@math.nagoya-u.ac.jp> X-j-chkmail-Score: MSGID : 453EFE24.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 453EFE24.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; subtyping:01 functors:01 afaik:01 functor:01 sig:01 compiler:01 sig:01 val:01 val:01 struct:01 'a-:01 functor:01 struct:01 'a-:01 dispatching:01 This would work but it isn't an option since I cannot get it to work with functors etc... AFAIK there's no way to specify a type must be a polymorphic variant without specfying any of it's members: if we are building a functor against: module type Evaluator= sig ... type 'a exp (*Is an exact polymorphic variant type *) ... end we won't be able to write something like: type 'a t=[ `Some_label of 'a | 'a exp ] since the compiler won't be able to detect 'a exp was a polymorphic variant (note: it looks like there could also be an issue on the freshness of the new label) trying to hack it like such: module type Evaluator= sig ... type 'a exp=[>`A_label of 'a ] (*Is an exact polymorphic variant type *) ... end won't work either.... As a final example I will put the code I'm trying to split in modules, it seems to be a simple case raising lots questions, so here we go (and I do know there are other ways to get my means...): module type Evaluator= sig type res type 'a exp val ops : ('a -> res) -> 'a exp -> res (*val eval : ('a exp as 'a) -> res*) end module Basic_ev: Evaluator= struct type res=int type 'a exp=[`Add of 'a * 'a | `Int of int | `Mul of 'a * 'a] let ops (eval:'a->res):('a exp -> res) = function | `Int n -> n | `Add(e1, e2) -> eval e1 + eval e2 | `Mul(e1, e2) -> eval e1 * eval e2 let rec eval (e : 'a exp as 'a) : res= ops eval e end module type Evaluator_extension= functor (Base:Evaluator)->(Evaluator with type res=Base.res) module Advanced_ev : Evaluator_extension= functor(Base:(Evaluator with type res=int))-> struct type res=int type 'a base= 'a Base.exp type 'a exp=[`Sub of 'a * 'a | 'a base ] let ops (eval:'a->res) :('a exp -> res) = function |`Sub(e1,e2) -> eval e1 - eval e2 | #base as x -> Base.ops eval x let rec eval (e : 'a exp as 'a) : res= ops eval e end Regards, Till On 10/25/06, Jacques Garrigue wrote: > Slight variation on Jon's answer: > > type c = [`B] > > let c = function > | `B -> () > > let b = function > | `A -> () > | #c as x -> c x > > which has exactly the same type as your original b. > > The way dispatching is typed in caml, you have to indicate explicitly > which cases you inherit from c. But it should no hinder extensibility. > > Jacques Garrigue > > From: "Till Varoquaux" > > I'm currently trying to split functions matching against given variant > > type and I'm running across this pb: > > > > let a= function > > | `A -> () > > | `B -> () > > > > doesn't split into > > > > let c=function > > | `B -> () > > > > let b =function > > | `A -> () > > | x -> c x > > > > since it messes up the type rules. I really want to avoid having to > > write down precise type informations (The point here is to have an > > extensible system)... > > > > I am sure this question has been asked loads of times (but I couldn't > > find the right thread in the archives) and I apologize for asking it > > yet again. > > > > Till >