[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Stephane Glondu <Stephane.Glondu@c...> |
| Subject: | Re: [Caml-list] Marshal and Polymorphism |
Hi,
Jonathan Bryant wrote:
> If I make the module have
>
> type = ('a, 'b) t
>
> in the module definition, can I use
>
> (Marshal.from_string ... : 'a)
>
> and get whatever 'a was defined as in the definition.
In the way I understood your message, you cannot. However, if you do
something like :
let get (table : ('a, 'b) t) index =
(Marshal.from_string ... : 'a)
The 'a type variable must be bound /inside/ a surrounding function
(and (Marshal.from_string val : 'a) should be forbidden outside a
function).
> For example, if
> it was a (string * int) t, would the function return a string?
Now, yes.
> Or would
> this be redundant (since Marshal.from_string already returns 'a)?
No! Actually, the return type of Marshal.from_string is [forall 'a.
'a], so it is different from any other 'a which could be already bound
at this moment. Therefore, you must explicitly tell the return type of
Marshall.from_string, even if it is polymorphic.
I hope this is clear.
Best regards,
--
Stephane Glondu