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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 9D6EA7ED34 for ; Tue, 3 Jul 2012 14:33:54 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jonathan.protzenko@gmail.com) identity=pra; client-ip=209.85.215.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="jonathan.protzenko@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of jonathan.protzenko@gmail.com designates 209.85.215.182 as permitted sender) identity=mailfrom; client-ip=209.85.215.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="jonathan.protzenko@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ey0-f182.google.com) identity=helo; client-ip=209.85.215.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="jonathan.protzenko@gmail.com"; x-sender="postmaster@mail-ey0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArACAPzl8k/RVde2jWdsb2JhbABFhVqgEpB2CCIBAQEBCQkLCRIGI4IYAQEBBBICDwQLAQUIARsSCgEBAwwGBQsNAgIFBBIIAwICCQMCAQIBEREBBQEKAREGDQEFAgEBDgcJh1oBAwsLnC0JA4tUT4JxhUwKGScDCleIcQEFDIEUihiFCIESA5U1gRKERIhQPoQA X-IronPort-AV: E=Sophos;i="4.77,515,1336341600"; d="scan'208";a="165419061" Received: from mail-ey0-f182.google.com ([209.85.215.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Jul 2012 14:33:54 +0200 Received: by eabm6 with SMTP id m6so3461975eab.27 for ; Tue, 03 Jul 2012 05:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=oXYjUBzd13VyJIgzTtPJGx5ckUz2YRXNpgeev2UAZo0=; b=JdE3i1XcWvt9+K67/XWLwpnWoiNXiArIqCD3gGS4n9EcBT0drrRlg599K93HZ/loyR nmE8o3jEp6+fpnjgbLKINtQ/utyW3p1eGW+CC2Vjc/j/QSD35i3Bqh2ft3LxAwax6SHd S76PmMM2fqHzO+1n137gyO1fUN/2Jh2Drxt5j/f02RdeoYgS8WOjA5M+hmnXBA9+w3IK otsnAr/yoZwQtPSe/Ot7VM5krR+TkhSJyjFTPiFwMvHm1kEEtwaFbzxCBdrD+4lF6ASR +RcMr6xmTzS5sojngQSXorIxud7PaOQYe4q+VeCWfMzKvyKpxqAQz8n6w5pkvH+7Wm4f Ru0g== Received: by 10.14.53.4 with SMTP id f4mr4292963eec.93.1341318832160; Tue, 03 Jul 2012 05:33:52 -0700 (PDT) Received: from [128.93.11.91] (sauternes.inria.fr. [128.93.11.91]) by mx.google.com with ESMTPS id z5sm44636465eem.3.2012.07.03.05.33.50 (version=SSLv3 cipher=OTHER); Tue, 03 Jul 2012 05:33:51 -0700 (PDT) Message-ID: <4FF2E6A9.3010807@gmail.com> Date: Tue, 03 Jul 2012 14:33:45 +0200 From: Jonathan Protzenko User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/16.0 Thunderbird/16.0a1 MIME-Version: 1.0 To: Philippe Veber CC: caml-list@inria.fr, jean-louis.giavitto@ircam.fr References: <4FF2E319.9070004@ircam.fr> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Initialization of a polymorphic field in a record The type you would like to assign to make1 is: make1: (∀x. x → bool) → t However, as far I understand, the type-system of OCaml introduces the ∀ quantifier in front of the function, namely: make1: ∀x. (x → bool) → t This means by the time you enter your make1 function, the f function has already lost its polymorphic type, since x has been "opened" already. I tried to eta-convert, but that doesn't work either: let make2 f = let g: 'b. 'b -> bool = fun (type t) (x: t) -> f x in { check = g };; Error: This expression has type t but an expression was expected of type t The type constructor t would escape its scope although I *did* think that would be legal. The only way I know of achieving that is by making make1 take a parameter of type t, that is, leave it up to the caller to wrap the function in a record with type t so as to keep the polymorphic nature of the function... I really did think there was a way of doing that with the newer (type t) features, so I'm hoping for someone to correct my example above :). Cheers, jonathan On Tue 03 Jul 2012 02:25:36 PM CEST, Philippe Veber wrote: > 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 > > >