English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Marshal and Polymorphism
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-08-04 (20:07)
From: Stephane Glondu <Stephane.Glondu@c...>
Subject: Re: [Caml-list] Marshal and Polymorphism

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

> 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