From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A5AC3BC8E for ; Tue, 15 Feb 2005 23:19:55 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j1FMJt6T012931 for ; Tue, 15 Feb 2005 23:19:55 +0100 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 XAA11621 for ; Tue, 15 Feb 2005 23:19:54 +0100 (MET) Received: from distrib3.mail.u-psud.fr (distrib3.mail.u-psud.fr [129.175.34.155]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1FMJsju020219 for ; Tue, 15 Feb 2005 23:19:54 +0100 Received: from intfiltre2.mail.u-psud.fr (intfiltre2.mail.u-psud.fr [129.175.34.150]) by distrib3.mail.u-psud.fr (8.12.10/8.12.0.Beta10) with ESMTP id j1FMJtmB025364 for ; Tue, 15 Feb 2005 23:19:55 +0100 Received: from post1.mail.u-psud.fr (post1.mail.u-psud.fr [129.175.34.87]) by intfiltre2.mail.u-psud.fr (8.12.10/8.12.0.Beta10) with ESMTP id j1FMJRM4015852 for ; Tue, 15 Feb 2005 23:19:54 +0100 Received: from tahiti.ile.u-psud.fr (tahiti.ile.u-psud.fr [172.17.4.7]) by post1.mail.u-psud.fr (8.12.10/8.12.0.Beta10) with ESMTP id j1FMHjeZ015171 for ; Tue, 15 Feb 2005 23:17:45 +0100 Received: from laposte.net (Naoned.ile.u-psud.fr [172.17.4.237]) by tahiti.ile.u-psud.fr (Postfix) with ESMTP id 863823CDA18 for ; Tue, 15 Feb 2005 23:17:19 +0100 (CET) Message-ID: <421275ED.1060607@laposte.net> Date: Tue, 15 Feb 2005 23:21:33 +0100 From: =?ISO-8859-1?Q?Olivier_P=E9r=E8s?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.6) Gecko/20040115 X-Accept-Language: br, fr, en MIME-Version: 1.0 To: Caml-list Subject: Re: [Caml-list] Polymorphic variant typing References: <7bf1f3b95c18eeda0ed169eb7f73d6f0@urbanet.ch> In-Reply-To: <7bf1f3b95c18eeda0ed169eb7f73d6f0@urbanet.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Scanned: by amavis X-Miltered: at concorde with ID 4212758B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4212758A.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 val:01 peres:98 peres:98 ...:98 polymorphic:01 typing:01 int:01 int:01 match:02 match:02 variant:02 types:02 float:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Gilles Dubochet a écrit : > let incr g x = match x with > | `Int i -> `Int (i+1) > | x -> (g x);; > > Receives type: > (([> `Int of int ] as 'a) -> ([> `Int of int ] as 'b)) -> 'a -> 'b Now, how about this : let incr x g = match x with | `Int i -> `Int (i+1) | x -> g x;; Doesn't it look like your code ? OCaml 3.08.2 types it as follows : val incr : ([> `Int of int ] as 'a) -> ('a -> ([> `Int of int ] as 'b)) -> 'b = This is more like it ! incr (`Int 1) (fun (`Int i) -> (`Int (i+1)));; - : [> `Int of int ] = `Int 2 incr (`Float 1.0) (fun x -> match x with (`Float f) -> (`Float (f +. 1.0)) | x -> x);; - : [> `Float of float | `Int of int ] = `Float 2. It remains to understand why the type of incr should depend upon the order in which the arguments are given... Yours, Olivier.