From: Jim Pryor <lists+caml@jimpryor.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Magic with fun (type t) ... ?
Date: Wed, 26 Jan 2011 17:34:36 -0500 [thread overview]
Message-ID: <20110126223436.GB5907@vaio.jimpryor.net> (raw)
In-Reply-To: <20110126221756.GA5907@vaio.jimpryor.net>
On Wed, Jan 26, 2011 at 05:17:56PM -0500, 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.
>
> Has this been noted before?
I expect it's probably harmless, because what could you do with the
exception value in question? Since it's leaked outside the scope of its
type declaration, I can't see any (unmagicky) way to
deconstruct it. But as I said, this behavior struck me as odd. I
would more have expected an error.
--
Jim Pryor
profjim@jimpryor.net
next prev parent reply other threads:[~2011-01-26 22:32 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
2011-01-27 6:13 ` Alain Frisch
2011-01-27 23:56 ` Guillaume Yziquel
2011-01-26 22:34 ` Jim Pryor [this message]
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=20110126223436.GB5907@vaio.jimpryor.net \
--to=lists+caml@jimpryor.net \
--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