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.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id B83B4BBAF for ; Wed, 11 Mar 2009 17:16:36 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.38,343,1233529200"; d="scan'208";a="25430750" Received: from macabane.inria.fr ([128.93.8.160]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA; 11 Mar 2009 17:16:36 +0100 Message-Id: From: Damien Doligez To: Caml-list List In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: [Caml-list] typing problem with sexplib and mutually recursive polymorphic types Date: Wed, 11 Mar 2009 17:16:36 +0100 References: <87prgoydy1.fsf@aryx.cs.uiuc.edu> <21952156.346634.1236751878001.JavaMail.www@wwinf1b03> <6D1EF1C5-3561-4D45-AE32-48F80EC84E58@cs.princeton.edu> X-Mailer: Apple Mail (2.930.3) X-Spam: no; 0.00; damien:01 damien:01 recursive:01 markus:01 mottl:01 haskell:01 ocaml:01 compiler:01 ocaml:01 compiler:01 inference:01 unify:01 type-checker:01 recursive:01 inference:01 On 2009-03-11, at 15:44, Markus Mottl wrote: > That's true, but unlike Haskell OCaml doesn't have mandatory types. > This means the user can't force the compiler to start out with > user-provided type declarations. The OCaml compiler will always run > type inference first and only try to unify the result with the > user-provided type declaration, i.e. when it's too late. That is not quite true any more. For example, I changed the type-checker a few years ago to start with the user-provided type when typing a let rec, in order to be able to debug my large recursive definitions. Note that I didn't do that from scrach, I used an infrastructure that was already present for seeding the type inference in some cases. IIRC, it is there for some object- oriented reason. Next time you have a type error on the wrong recursive call, try annotating the function at its definition point. For example, compare the error messages for: let rec f x = g x [] and g x l = match l with | [] -> f "a" | [a] -> f 1 | [a; b] -> f 2 | _ -> f 3 ;; versus: let rec f (x : int) = g x [] and g x l = match l with | [] -> f "a" | [a] -> f 1 | [a; b] -> f 2 | _ -> f 3 ;; Note that your second sentence is still right, because type annotations are only used in this way in a limited number of cases (let rec is one example). -- Damien