Version française
Home     About     Download     Resources     Contact us    
Browse thread
module type...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrew Bagdanov <andrew@s...>
Subject: Re: [Caml-list] Specifying abstract type in a record
josh writes:
 > OK,  Here's what I'm trying to do:
 > 
 > # type doer = { file_name:string ; actor: ('a -> unit) };;
 > 
 > But when I do this, it tells me that I've got "Unbound type parameter 'a ".
 > 

You need to add a type parameter to the doer type:

 # type 'a doer = {file_name:string; actor: ('a -> unit) };;
 type 'a doer = { file_name : string; actor : 'a -> unit; }

This binds the type parameter 'a in your original definition.  Now
things should work the way you want:

 # let b = {file_name = "one"; actor = (fun x -> () ) };;
 val b : 'a doer = {file_name = "one"; actor = <fun>}
 # b.actor 10;;
 - : unit = ()

Note that in this definition, b.actor remains polymorphic.  If you
were to do this:

 # let b = {file_name = "one"; actor = (fun x -> Printf.printf "%d\n" x) };;
 val b : int doer = {file_name = "one"; actor = <fun>}

then 'a becones concrete (int).

Hope this helps...

-Andy