caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Zheng Li <li@pps.jussieu.fr>
To: caml-list@inria.fr
Subject: Re: Type_of?
Date: Sat, 05 Jan 2008 21:33:25 +0100	[thread overview]
Message-ID: <87sl1cvwq2.fsf@pps.jussieu.fr> (raw)
In-Reply-To: <712252.79789.qm@web54603.mail.re2.yahoo.com>


Hello, 

Dario Teixeira <darioteixeira@yahoo.com> writes:
> 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?

Do you have any restriction in bounding them as pairs? The simplest
example come into my mind is like:

# let produce () :'a = [`Zero; `One 1] and consume (l:'a) = ();;
val produce : unit -> [> `One of int | `Zero ] list = <fun>
val consume : [> `One of int | `Zero ] list -> unit = <fun>

In this way, you don't have to write the variants manually, since
"ocamlc -i" can inference it and the type 'a in the pairs are always
bounded.

HTH.
-- 
Zheng Li
http://www.pps.jussieu.fr/~li


  parent reply	other threads:[~2008-01-05 20:13 UTC|newest]

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

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=87sl1cvwq2.fsf@pps.jussieu.fr \
    --to=li@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    /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).