caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Type_of?
Date: Sat, 05 Jan 2008 17:12:24 +0000	[thread overview]
Message-ID: <477FBA78.8060400@ed.ac.uk> (raw)
In-Reply-To: <712252.79789.qm@web54603.mail.re2.yahoo.com>

Dario Teixeira wrote:
> So, imagine I have a module with only two functions.  The first, "make_doc",
> uses XHTML.M and its signature is therefore quite complex.  This is what
> "ocamlc -i" tells me:
[...]
> The second function, "unpickle_doc", uses the Marshal module to deserialise
> from a string a previously pickled doc.  This is the definition of this
> function:  (note that I've used copy & paste of the previous output of
> "ocamlc -i" to provide the explicit type annotation)
[...]
> Now, this works fine.  It is however error prone, since if the signature
> of make_doc changes somewhat and I forget to update the type annotation in
> unpickle_doc, then I get a nasty runtime segfault.  So this is my question:
> since the return type of make_doc is known at compile-time, is there any
> way I can tell the compiler that the return type of unpickle_doc should be
> the same as make_doc's?

One way is to use both functions in a context which requires the return 
types to be the same.  For example, you could use both functions to 
create the elements of a list:

   let rec unpickle_doc str =
     let _unify_return_types _ = [unpickle_doc ""; make_doc ""] in
       Marshal.from_string str 0

Jeremy.


  reply	other threads:[~2008-01-05 17:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-05 16:41 Type_of? Dario Teixeira
2008-01-05 17:12 ` Jeremy Yallop [this message]
2008-01-05 17:43 ` [Caml-list] Type_of? Arnaud Spiwack
2008-01-05 20:33 ` Type_of? Zheng Li
  -- strict thread matches above, loose matches on Subject: below --
2005-04-18  9:18 type of == Christophe DEHLINGER
2005-04-18 11:27 ` [Caml-list] " Jon Harrop
2005-04-18 12:11   ` Andreas Rossberg
2005-04-18 13:10     ` Christophe DEHLINGER
2005-04-18 14:28     ` Jon Harrop
2005-04-18 16:16   ` Remi Vanicat

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=477FBA78.8060400@ed.ac.uk \
    --to=jeremy.yallop@ed.ac.uk \
    --cc=caml-list@yquem.inria.fr \
    --cc=darioteixeira@yahoo.com \
    /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;
as well as URLs for NNTP newsgroup(s).