From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id D4B557ED34 for ; Tue, 3 Jul 2012 14:25:58 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=209.85.220.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of philippe.veber@gmail.com designates 209.85.220.182 as permitted sender) identity=mailfrom; client-ip=209.85.220.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vc0-f182.google.com) identity=helo; client-ip=209.85.220.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-vc0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An4CABjk8k/RVdy2kWdsb2JhbABFpWyICAGIbQgiAQEBAQkJDQcSKYIYAQEBAwESAhMZARsSCwEDAQsGBQsaISIBEQEFAQoSGQgKBwmHWgEDBgULnDMJA4wjgnGFTAoZJwMKV4hxAQUMkUYDlTWBEo0UPoJMgTQ X-IronPort-AV: E=Sophos;i="4.77,515,1336341600"; d="scan'208";a="149487552" Received: from mail-vc0-f182.google.com ([209.85.220.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Jul 2012 14:25:57 +0200 Received: by vcbfy7 with SMTP id fy7so6696043vcb.27 for ; Tue, 03 Jul 2012 05:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=+I4mO0q1gwTBcB5P6oI2BYHx8OKFtPVTSGbnOkUwRKs=; b=caOBmDfZCRuauyhE4KESkkjAgr9Myt8bBGX39xFI+7ECcmypStWWMalqL5HYC3MAUQ HUDFVu1UlQKZ9+/f4qCyZ7i5K/w52zN47IXef/YSviSiLbCz3zAt9QQo8Gvu0QL5WL17 stCx54eLf17aQKOWSq/OwOrGVXlhHZ8dMkHUSdnZfGRceNIMx4xMRBAbd6fC4lFQBmEt 3ZUxicpjPJAt2OH5BU8wqx4mssdx7LuDJyj3rYrOEkJtnzxblOlRBWqck+s9fGoxH1EB 1Fxa8xhI0BcUhc62fEBZTrcZeh+WadsfjZdsRv2lNGPG48L5UTkVCRxzkwLUzSQ33BBU FI0w== Received: by 10.220.240.148 with SMTP id la20mr8053759vcb.39.1341318356793; Tue, 03 Jul 2012 05:25:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.65.212 with HTTP; Tue, 3 Jul 2012 05:25:36 -0700 (PDT) In-Reply-To: <4FF2E319.9070004@ircam.fr> References: <4FF2E319.9070004@ircam.fr> From: Philippe Veber Date: Tue, 3 Jul 2012 14:25:36 +0200 Message-ID: To: jean-louis.giavitto@ircam.fr Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=14dae9cfc1302ff7f304c3ec04bc X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Initialization of a polymorphic field in a record --14dae9cfc1302ff7f304c3ec04bc Content-Type: text/plain; charset=ISO-8859-1 Hi, how about that: # type t = { check : 'a. 'a -> bool };; type t = { check : 'a. 'a -> bool; } # let return_true : 'a. 'a -> bool = fun _ -> true;; val return_true : 'a -> bool = # let make1 () = { check = return_true; };; val make1 : unit -> t = cheers, Philippe. 2012/7/3 Jean-Louis Giavitto > Hello. > > I am trying to build a record with a polymorphic field and I am unable to > initialize this field. The problem can be summarized as follow. The > following definitions works well: > > type t = { check : 'a. 'a -> bool } > > let return_true _ = true > > let make1 () = { check = return_true; } > > But this definition raises an error: > > let make2 f = { check = f; } > > with the message: > > Error: This field value has type 'a -> bool which is less general than > 'b. 'b -> bool > > Note that > > let return_false _ = true > > let make3 c = { check = if c then return_false else return_true; } > > is working but that > > let g c = if c then return_false else return_true > let make4 c = { check = g c; } > > raises the same error message. Making explicit the argument of make does > not helps: > > let make5 f = { check = f; } > in make5 return_true > > (same error message). And making explicit the type of make does not help > neither: > > let make6 : 'a. ('a -> bool) -> t > = function f -> { check = f; } > > (same error message). > > > > Do you have an idea how I can specify a function similar to make to buid a > record of type t? > > In the real life, the argument f will be the result of a computation and > instead of a simple signature 'a -> bool, I must deal with a signature > > 'a 'b. (('b) #SomeClass as 'a) * 'b -> bool > > > Thanks for your advice, > Jean-Louis Giavitto. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/**wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-**bugs > > --14dae9cfc1302ff7f304c3ec04bc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

how about that:

# type t = =3D { check : 'a. 'a -> bool };;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0
type t =3D { check : '= ;a. 'a -> bool; }=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0

# let return_true = : 'a. 'a -> bool =3D fun _ -> true;;=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
val return_true : 'a -> bool =3D <fun>=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0

# let make1 () =3D { check =3D return_t= rue; };;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
val make1 : unit -> t = =3D <fun>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0

cheers,
=A0 Philippe.


2012/7/3 Jean-Louis Giavitto <jean-louis.giavitto@ircam.fr>
Hello.

I am trying to build a record with a polymorphic field and I am unable to i= nitialize this field. The problem can be summarized as follow. The followin= g definitions works well:

=A0 =A0type t =3D { check : 'a. 'a -> bool }

=A0 =A0let return_true _ =3D true

=A0 =A0let make1 () =3D { check =3D return_true; }

But this definition raises an error:

=A0 =A0let make2 f =3D { check =3D f; }

with the message:

=A0 Error: This field value has type 'a -> bool which is less genera= l than
=A0 =A0 =A0 =A0 =A0'b. 'b -> bool

Note that

=A0 =A0let return_false _ =3D true

=A0 =A0let make3 c =3D { check =3D if c then return_false else return_true;= }

is working but that

=A0 =A0let g c =3D if c then return_false else return_true
=A0 =A0let make4 c =3D { check =3D g c; }

raises the same error message. Making explicit the argument of make does no= t helps:

=A0 let make5 f =3D { check =3D f; }
=A0 in make5 return_true

(same error message). And making explicit the type of make does not help ne= ither:

=A0 let make6 : 'a. ('a -> bool) -> t
=A0 =3D function f -> { check =3D f; }

(same error message).



Do you have an idea how I can specify a function similar to make to buid a = record of type t?

In the real life, the argument f will be the result of a computation and in= stead of a simple signature 'a -> bool, I must deal with a signature=

=A0 =A0'a 'b. (('b) #SomeClass as 'a) * 'b -> bool

Thanks for your advice,
Jean-Louis Giavitto.

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners<= /a>
Bug reports:
http://caml.inria.fr/bin/caml-bugs


--14dae9cfc1302ff7f304c3ec04bc--