caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Initialization of a polymorphic field in a record
@ 2012-07-03 12:18 Jean-Louis Giavitto
  2012-07-03 12:25 ` Philippe Veber
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Louis Giavitto @ 2012-07-03 12:18 UTC (permalink / raw)
  To: caml-list

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-03 12:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-03 12:18 [Caml-list] Initialization of a polymorphic field in a record Jean-Louis Giavitto
2012-07-03 12:25 ` Philippe Veber
2012-07-03 12:33   ` Jonathan Protzenko
2012-07-03 12:42     ` Gabriel Scherer

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).