caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: colanderman@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Unexpected '_a problem
Date: Fri, 04 Aug 2006 11:42:39 +0900 (JST)	[thread overview]
Message-ID: <20060804.114239.193683263.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <875c7e070608021057rfb89914x1d6b9c6e7e4d7ce0@mail.gmail.com>

From: "Chris King" <colanderman@gmail.com>
> Okay, that (and Christophe's explanation) explains why hiding
> everything in a module works.  Thanks everyone for your help!  It
> seems I will have to use Obj.magic to get the type I want but at least
> its use in this situation seems both safe and warranted.

There are no "safe" uses of Obj.magic. It just happens to work in some
cases, but it is strongly discouraged to use it to get around the type
system, particularly when there are other ways to reach the same
result.

type 'a bar_t = Bar of <bar: ('a -> unit) -> unit> ;;
let create_bar () = Bar (object method bar (_: 'a) = () end);;
let b = create_bar ();;
let Bar b = b;;

Note that you need two definitions, as mixing the application with the
extraction would loose the polymorphism.
If you still want to use Obj.magic, remember to put complete type
annotions on both its input and output, as the lack of type
information may break the compiler.

Jacques Garrigue


  reply	other threads:[~2006-08-04  2:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-01 20:47 Chris King
2006-08-01 21:20 ` [Caml-list] " Andreas Rossberg
2006-08-01 22:09   ` Remi Vanicat
2006-08-02  7:00     ` Alain Frisch
2006-08-02 17:57       ` Chris King
2006-08-04  2:42         ` Jacques Garrigue [this message]
2006-08-04 14:18           ` Chris King
2006-08-02  7:03     ` Christophe Dehlinger
2006-08-02  8:07       ` Andreas Rossberg

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=20060804.114239.193683263.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=colanderman@gmail.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).