Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Stephane Glondu <Stephane.Glondu@crans.org>
To: jtbryant@valdosta.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Marshal and Polymorphism
Date: Thu, 04 Aug 2005 13:06:04 -0700	[thread overview]
Message-ID: <42F2752C.9070904@crans.org> (raw)
In-Reply-To: <1123179836.3276.76.camel@starlight.valdosta.edu>

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


  reply	other threads:[~2005-08-04 20:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-04 18:23 Jonathan Bryant
2005-08-04 20:06 ` Stephane Glondu [this message]
2005-08-04 20:39   ` [Caml-list] " Jonathan Bryant
2005-08-04 21:57     ` Stephane Glondu
2005-08-04 23:17     ` skaller

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=42F2752C.9070904@crans.org \
    --to=stephane.glondu@crans.org \
    --cc=caml-list@inria.fr \
    --cc=jtbryant@valdosta.edu \
    /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