From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A271C7FBFE for ; Fri, 23 Jan 2015 16:05:07 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of arnaud.spiwack@gmail.com) identity=pra; client-ip=209.85.212.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of arnaud.spiwack@gmail.com designates 209.85.212.174 as permitted sender) identity=mailfrom; client-ip=209.85.212.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f174.google.com) identity=helo; client-ip=209.85.212.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="postmaster@mail-wi0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuEBAHpiwlTRVdSum2dsb2JhbABag1hYBIJ8s36NaYFphXGBEgdDAQEBAQERAQEBAQEGCwsJFC6EDQEBAwESEQQZAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBhMSEId2AwkIDaBxkE8+MYsuhGKKYScDCoRlAQoBAQEYAQUOj2aCc4FBBYQ/CY1og1iBd4EkJo8hEiOBFVuDNj0xgkMBAQE X-IPAS-Result: AuEBAHpiwlTRVdSum2dsb2JhbABag1hYBIJ8s36NaYFphXGBEgdDAQEBAQERAQEBAQEGCwsJFC6EDQEBAwESEQQZAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBhMSEId2AwkIDaBxkE8+MYsuhGKKYScDCoRlAQoBAQEYAQUOj2aCc4FBBYQ/CY1og1iBd4EkJo8hEiOBFVuDNj0xgkMBAQE X-IronPort-AV: E=Sophos;i="5.09,454,1418079600"; d="scan'208";a="97484118" Received: from mail-wi0-f174.google.com ([209.85.212.174]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jan 2015 16:05:06 +0100 Received: by mail-wi0-f174.google.com with SMTP id n3so3455797wiv.1; Fri, 23 Jan 2015 07:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ax34fCPZtKUBZAAIjhnU7jqNWi/9osWeMQSCv/jkjRw=; b=j3tBcAvavP5oYkmVJK/CZ0xwtk23t9phdA5cUMM+h7X+iuQJM+9f8yQj4n0psnyxmx McRN22vODMHelF1YtOsRtILEvonHUih5UW9JQuer4OxNAQI6fjD+WvP87qfejWtJ4bJf bldYLDwgUKJ9fR/Auz7WFPK06w4dki+65X4/gt8dFcfJPMVSoleaiGBOi3bP93cyperi cRY1AdhkXG8hABjr5r/ZvxSRNxvQLTOH3CDSaYlaTBj97fwOadSLtXc1vi/zGMdM803g 4ySU/e3mdNo7TJdvfxafqIWsuAYVFxkOakDUKylXkWtzqm6HWHAYGZeG8A9ygsCZS7HV Q9mQ== X-Received: by 10.194.237.202 with SMTP id ve10mr15314434wjc.36.1422025506758; Fri, 23 Jan 2015 07:05:06 -0800 (PST) MIME-Version: 1.0 Sender: arnaud.spiwack@gmail.com Received: by 10.217.180.9 with HTTP; Fri, 23 Jan 2015 07:04:26 -0800 (PST) In-Reply-To: <20150123154323.1fc8e7d8@alcazar2> References: <20150123154323.1fc8e7d8@alcazar2> From: Arnaud Spiwack Date: Fri, 23 Jan 2015 16:04:26 +0100 X-Google-Sender-Auth: hwrdV1uJLVGcp0ssuTwBfPCpW-8 Message-ID: To: Maxence Guesdon Cc: OCaML Mailing List Content-Type: multipart/alternative; boundary=089e01493f063126c8050d531dff X-Validation-by: arnaud@spiwack.net Subject: Re: [Caml-list] Strange type inference error --089e01493f063126c8050d531dff Content-Type: text/plain; charset=UTF-8 The error message is correct in that `g` is not a value (and so the value restriction bites you). At the end of a module, no non-generalisable variables must be left, so Ocaml complains (you will notice, indeed, that in a toplevel, ocaml will give you the non-generalisable type without complaining). I'm guessing ocaml has a relaxed view of values where `let x = in ` is considered a value, which would be why `f` properly generalises. On 23 January 2015 at 15:43, Maxence Guesdon wrote: > Hello, > > I encountered a strange typing problem and reduced it to the following > code example: > > ====[t.ml]==== > let mk_env () = None > let list_of_string (s: string) = [s] > > let apply : 'a -> 'a option -> string list -> 'a * string list = > fun acc env l -> (acc, ["hello"]) > > let f = > let tmpl = ["coucou"] in > fun ?(env=mk_env()) -> > fun ~x -> > fun () -> apply () env tmpl > > let g = > let tmpl = list_of_string "coucou" in > fun ?(env=mk_env()) -> > fun ~x -> > fun () -> apply () env tmpl > ==== > Note that f and g only differ on the way tmpl is defined. > > When I compile this file with ocaml 4.02.1, I get the following error: > File "t.ml", line 14, characters 3-119: > Error: The type of this expression, > ?env:unit option -> x:'_a -> unit -> unit * string list, > contains type variables that cannot be generalized > > Am I missing something or should I file a bug report ? > > Regards, > > Maxence > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --089e01493f063126c8050d531dff Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The error message is correct in that `g` is not a value (a= nd so the value restriction bites you). At the end of a module, no non-gene= ralisable variables must be left, so Ocaml complains (you will notice, inde= ed, that in a toplevel, ocaml will give you the non-generalisable type with= out complaining).

I'm guessing ocaml has a relaxed view of value= s where `let x =3D <value> in <value>` is considered a value, w= hich would be why `f` properly generalises.

On 23 January 2015 at 15:43, Maxence Gu= esdon <Maxence.Guesdon@inria.fr> wrote:
Hello,

I encountered a strange typing problem and reduced it to the following
code example:

=3D=3D=3D=3D[t.ml]=3D=3D=3D= =3D
let mk_env () =3D None
let list_of_string (s: string) =3D [s]

let apply : 'a -> 'a option -> string list -> 'a * str= ing list =3D
=C2=A0 fun acc env l -> (acc, ["hello"])

let f =3D
=C2=A0 =C2=A0let tmpl =3D ["coucou"] in
=C2=A0 =C2=A0 fun ?(env=3Dmk_env()) ->
=C2=A0 =C2=A0 =C2=A0 fun ~x ->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fun () -> apply () env tmpl

let g =3D
=C2=A0 =C2=A0let tmpl =3D list_of_string "coucou" in
=C2=A0 =C2=A0 fun ?(env=3Dmk_env()) ->
=C2=A0 =C2=A0 =C2=A0 fun ~x ->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fun () -> apply () env tmpl
=3D=3D=3D=3D
Note that f and g only differ on the way tmpl is defined.

When I compile this file with ocaml 4.02.1, I get the following error:
File "t.ml", line 1= 4, characters 3-119:
Error: The type of this expression,
=C2=A0 =C2=A0 =C2=A0 =C2=A0?env:unit option -> x:'_a -> unit ->= ; unit * string list,
=C2=A0 =C2=A0 =C2=A0 =C2=A0contains type variables that cannot be generaliz= ed

Am I missing something or should I file a bug report ?

Regards,

Maxence

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--089e01493f063126c8050d531dff--