From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E9390BC84 for ; Tue, 26 Apr 2005 14:00:22 +0200 (CEST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j3QC0McB018080 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 26 Apr 2005 14:00:22 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id 7871019E896; Tue, 26 Apr 2005 14:00:22 +0200 (CEST) Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25085-08; Tue, 26 Apr 2005 14:00:22 +0200 (CEST) Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id 6425219E877; Tue, 26 Apr 2005 14:00:22 +0200 (CEST) Received: from pc9-152 (pc9-152 [129.175.9.152]) by smtp.lri.fr (Postfix) with ESMTP id CAD22CED9B; Tue, 26 Apr 2005 14:00:21 +0200 (CEST) Received: from filliatr by pc9-152 with local (Exim 3.36 #1 (Debian)) id 1DQOjm-00067B-00; Tue, 26 Apr 2005 14:00:22 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17006.11606.297786.728905@gargle.gargle.HOWL> Date: Tue, 26 Apr 2005 14:00:22 +0200 To: Julien Verlaguet Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Type inference question In-Reply-To: References: X-Mailer: VM 7.18 under Emacs 21.3.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at nez-perce with ID 426E2D56.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 inference:01 filliatre:01 filliatre:01 lri:01 myfun:01 stdin:01 myfun:01 stdin:01 forall:01 instanciated:01 ocaml:01 marshalling:01 ...:98 writes:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Julien Verlaguet writes: > I have the following function definition : > > let myfun param= > let res=Marshal.from_channel stdin [] in > if res=param then > res > else res > > I was expecting : myfun : 'a -> 'a > > I got instead : myfun : 'a -> 'b > > Is it normal ? Yes. "Marshal.from_channel stdin []" has type 'a and this type is generalized in the let/in construct, giving res the type "forall 'a. 'a". In the test "res = param", the type of res is instanciated on the type of param, but this does not affect the type of the result. It would be better if Marshal.from_channel would be given a type that cannot be generalized ('_a) but I don't think that the ocaml type system can do this. Anyway, it is always a good idea to use a type constraint when using marshalling functions, as in let (x : tau) = Marshal.from_channel ... Hope this helps, -- Jean-Christophe