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=2.0 required=5.0 tests=AWL,DNS_FROM_RFC_POST, 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id CF30FBBAF for ; Wed, 11 Mar 2009 05:25:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlwCADfatklKfSwek2dsb2JhbACUbz8BAQEBCQkKCREDqy6BB495AQMBA4QKBg X-IronPort-AV: E=Sophos;i="4.38,339,1233529200"; d="scan'208";a="22359290" Received: from yx-out-2324.google.com ([74.125.44.30]) by mail2-smtp-roc.national.inria.fr with ESMTP; 11 Mar 2009 05:25:01 +0100 Received: by yx-out-2324.google.com with SMTP id 3so1121062yxj.27 for ; Tue, 10 Mar 2009 21:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=s004UxC+/2dUU//6iwyIEpurYiZ75cFIt7UmwwVoKHI=; b=c6bk5iT8J4vuSZwt5bEfDddREKf1fG2sq6l3qnIebZiZRgSQaP4xCxMeCgQqobfOiR W9XK++vrvsJ/HQ2oh0hLC89UAGcyw9/YnMpUJHEm8y7ZMnpVT4EfBTsh9ibBwv13kwqM DGKXzNFPYIK2LRbAAKMg52LFrrGV+/qEJlICw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=vEEalnf9EXzFvS0tCOJQmx5LaBAjsY7Yy3BnRFBleKmR+77MutGLUyub1t/g53AHxA 9K381kJA5BHjcWlFk9k1xfDxYEnVuh013m+vCOdGRdeT2V23nWWnLsOnalJG1lXNj9AX UyBuKG/OPjj1q6bBeSmf9cre2ocTedl50P0Nc= MIME-Version: 1.0 Received: by 10.220.99.149 with SMTP id u21mr1751310vcn.94.1236745500325; Tue, 10 Mar 2009 21:25:00 -0700 (PDT) In-Reply-To: <87prgoydy1.fsf@aryx.cs.uiuc.edu> References: <87prgoydy1.fsf@aryx.cs.uiuc.edu> Date: Wed, 11 Mar 2009 00:25:00 -0400 Message-ID: Subject: Re: [Caml-list] typing problem with sexplib and mutually recursive polymorphic types From: Markus Mottl To: Yoann Padioleau Cc: Caml-list List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; recursive:01 markus:01 mottl:01 markus:01 mottl:01 ocaml:01 foo:01 sexp:01 sexp:01 ocaml:01 'int':01 'int':01 'let:01 recursive:01 foo:01 On Tue, Mar 10, 2009 at 22:45, Yoann Padioleau wrote: > But then the ocaml type system refuses to type this second file with the > error message: > File "foo2.ml", line 22, characters 48-67: > This expression has type Sexp.t -> string but is here used with type > =A0Sexp.t -> int > > Apparently the problem is that ocaml was not able to generalize > the type of x1_of_sexp and that it's first utilisation with an 'int' > force the x1_of_sexp to always return an 'int' instead of a 'string' > in the second case. Is there a way to rewrite this generated code > to avoid this typing problem ? Is it because of those > =A0'let _loc =3D ... in fun ... ->" =A0that distrubs the ocaml type syste= m ? This has to do with recursive type definitions, not with generating closures with _loc. The following is similar and does not compile either: let rec foo () =3D [] and bar () =3D "asdf" :: foo () and bla () =3D 42 :: foo () These definitions are clearly sound, but the type checker doesn't get it. Note, however, that the following works: let foo () =3D [] let rec bar () =3D "asdf" :: foo () and bla () =3D 42 :: foo () You can apply the same trick in your specific example by simply moving the type definition of x1 out of the cycle with x2 and x3. Cheers, Markus --=20 Markus Mottl http://www.ocaml.info markus.mottl@gmail.com