From: David Allsopp <dra-news@metastack.com>
To: "'Jim Pryor'" <lists+caml@jimpryor.net>,
"'caml-list@inria.fr'" <caml-list@inria.fr>
Subject: RE: [Caml-list] Magic with fun (type t) ... ?
Date: Wed, 26 Jan 2011 22:33:17 +0000 [thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9490BA1EA@Remus.metastack.local> (raw)
In-Reply-To: <20110126221756.GA5907@vaio.jimpryor.net>
Jim Pryor wrote:
> I expect this is bad coding style, and should not be relied on. However,
> I was surprised at the behavior, and wondered whether it was intended:
>
> # let f = fun (type t) x ->
> let module M = struct exception E of t end in
> M.E x;;
> val f : 'a -> exn = <fun>
>
> f is polymorphic, as we expect:
>
> # f 1;;
> - : exn = E 1
> # f "s";;
> - : exn = E "s"
>
> But now notice:
>
> # f ();;
> - : exn = E 0
> # f None;;
> - : exn = E 0
>
> It appears that non-heap values are always getting magicked into ints.
I think there are other situations (I can't remember how you can force them) where the toploop displays the "wrong" things. As I understand it, the compiler/interpreter really has to jump through hoops sometimes to display the correct version of a value because the value representation throws away so much (virtually) of the typing information.
> Has this been noted before?
However, this is weird since () and the constructor None are not equal in OCaml-land (they happen to have equivalent representation, but that's not the same thing):
# f () = f None;;
- : bool = true
David
next prev parent reply other threads:[~2011-01-26 22:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-26 22:17 Jim Pryor
2011-01-26 22:33 ` David Allsopp [this message]
2011-01-27 6:13 ` Alain Frisch
2011-01-27 23:56 ` Guillaume Yziquel
2011-01-26 22:34 ` Jim Pryor
2011-01-26 23:07 ` Guillaume Yziquel
2011-01-26 23:11 ` Gabriel Scherer
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=E51C5B015DBD1348A1D85763337FB6D9490BA1EA@Remus.metastack.local \
--to=dra-news@metastack.com \
--cc=caml-list@inria.fr \
--cc=lists+caml@jimpryor.net \
/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