From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p0QNC05i023511 for ; Thu, 27 Jan 2011 00:12:00 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0BAA45QE3RVdi2kGdsb2JhbACWKYY2AYgSCBUBAQIJCQwHEQQgoieKAIIXhRsuiFkBAQMFhUoEgWKJMoEV X-IronPort-AV: E=Sophos;i="4.60,382,1291590000"; d="scan'208";a="86366179" Received: from mail-qy0-f182.google.com ([209.85.216.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 27 Jan 2011 00:11:54 +0100 Received: by qyk36 with SMTP id 36so1521857qyk.6 for ; Wed, 26 Jan 2011 15:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=H3Hi/jpBXi4nSiZ4zVrYmNqw5UK21p2crIWEHMOhQwE=; b=wu52SQ8klbnOQ66u0FHagW5LG+Xm5FWrD/F1UFbs/CBABYkt4ZPR7fNG6ii8CAEgGm kI+3/IBCf0nNgD2TqVItOYzmlUggTO5uaIUQ8oz4sEawr5b0erFfzAJAyUv2Neq+0rei TxLm8VaS72dGvsCtt1yIW19eao/36HfjhHOl0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=UbBWtRPaoQDuT3GMuWuI3H1fPAszCcqcNf6snYR1mIWltfrTjGFuICbBqtgrzIB183 HFCSPhTtQMwDZ1XHT2T8lXFrBzZbkZbMeGQp+lcUSTmvADZYY+trjOKZ9UzCV3qo37Vf bHIxxmmIqEGZ7n7KKsJINLRbtSLaQ7fD7/4zo= Received: by 10.229.249.17 with SMTP id mi17mr893823qcb.123.1296083511787; Wed, 26 Jan 2011 15:11:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.62.9 with HTTP; Wed, 26 Jan 2011 15:11:31 -0800 (PST) In-Reply-To: <20110126221756.GA5907@vaio.jimpryor.net> References: <20110126221756.GA5907@vaio.jimpryor.net> From: Gabriel Scherer Date: Thu, 27 Jan 2011 00:11:31 +0100 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016e64cc91851bfd9049ac7f512 Subject: Re: [Caml-list] Magic with fun (type t) ... ? --0016e64cc91851bfd9049ac7f512 Content-Type: text/plain; charset=ISO-8859-1 Local modules are usually "safe" in the sense that the type system checks that the local types do not escape the whole expression. # let test = let module Local = struct type t = Foo end in Local.Foo;; Error: This `let module' expression has type Local.t In this type, the locally bound module name Local escapes its scope However, exceptions do not create a local type, they instead augment the global open-ended "exn" type, so the type-checker won't detect the leak. Finally, you don't want to disallow local exception declarations, as they're very useful in various situations -- simply moving an existing module to a local scope. The use of the new (type t) construct to declare local polymorphic exceptions is also useful in some cases. See for example: http://ocaml.janestreet.com/?q=node/18#comment-190 (I agree that the type regression when escaping is quite weird and should be avoided if possible.) On Wed, Jan 26, 2011 at 11:17 PM, 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 = > > 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? > > -- > Jim Pryor > profjimm@jimpryor.net > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --0016e64cc91851bfd9049ac7f512 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Local modules are usually "safe" in the sense that the type syste= m checks that the local types do not escape the whole expression.

<= /div>
=A0=A0# let test =3D
=A0=A0 =A0 =A0let module Loca= l =3D struct type t =3D Foo end
=A0=A0 =A0 =A0in Local.Foo;;
=A0=A0Error: This `let module&#= 39; expression has type Local.t
=A0=A0In this type, the locally b= ound module name Local escapes its scope

However, = exceptions do not create a local type, they instead augment the global open= -ended "exn" type, so the=A0type-checker won't detect the lea= k.

Finally, you don't want to disallow local exception= declarations, as they're very useful in various situations -- simply m= oving an existing module to a local scope.
The use of the new (ty= pe t) construct to declare local polymorphic exceptions is also useful in s= ome cases. See for example:=A0http://ocaml.janestreet.com/?q=3Dnode/18#comment-190




On Wed, Jan 26, 2011 at 11:17 PM, Jim Pryor = <lists+ca= ml@jimpryor.net> 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 =3D fun (type t) x ->
=A0 =A0let module M =3D struct exception E of t end in
=A0 =A0M.E x;;
val f : 'a -> exn =3D <fun>

f is polymorphic, as we expect:

# f 1;;
- : exn =3D E 1
# f "s";;
- : exn =3D E "s"

But now notice:

# f ();;
- : exn =3D E 0
# f None;;
- : exn =3D E 0

It appears that non-heap values are always getting magicked into ints.

Has this been noted before?

--
Jim Pryor
profjimm@jimpryor.net

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--0016e64cc91851bfd9049ac7f512--