caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@gmail.com>
To: jean-louis.giavitto@ircam.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Initialization of a polymorphic field in a record
Date: Tue, 3 Jul 2012 14:25:36 +0200	[thread overview]
Message-ID: <CAOOOohTimG6MZ9vrXDFW4n1tzCXE8giuob6Wgm7iEB9nM4sZTg@mail.gmail.com> (raw)
In-Reply-To: <4FF2E319.9070004@ircam.fr>

[-- Attachment #1: Type: text/plain, Size: 2175 bytes --]

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 =
<fun>

# let make1 () = { check = return_true;
};;
val make1 : unit -> t =
<fun>

cheers,
  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
> 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<https://sympa-roc.inria.fr/wws/info/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
>

[-- Attachment #2: Type: text/html, Size: 4255 bytes --]

  reply	other threads:[~2012-07-03 12:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-03 12:18 Jean-Louis Giavitto
2012-07-03 12:25 ` Philippe Veber [this message]
2012-07-03 12:33   ` Jonathan Protzenko
2012-07-03 12:42     ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOOOohTimG6MZ9vrXDFW4n1tzCXE8giuob6Wgm7iEB9nM4sZTg@mail.gmail.com \
    --to=philippe.veber@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=jean-louis.giavitto@ircam.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).