From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 1C676BC37 for ; Tue, 9 Feb 2010 19:09:56 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlECAMczcUvRVdO1imdsb2JhbACDM413ghKHSjwBAQEKCQwHEQWuUC6BSoUxiHEBAQMFg3RbBA X-IronPort-AV: E=Sophos;i="4.49,437,1262559600"; d="scan'208";a="44122820" Received: from mail-yw0-f181.google.com ([209.85.211.181]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Feb 2010 19:09:55 +0100 Received: by ywh11 with SMTP id 11so2067762ywh.9 for ; Tue, 09 Feb 2010 10:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=U8k56K2oh641mmaBlQOZHSExoyM5cvTTy1QE9RDCng4=; b=qyZrwpIl7QQBWDw5k4BU1+hS+qUsKl9XOElat9+QAb10+UipzQNFOYnWFWCQl7+ktW 4VIody4Kh2dpvtt078IMiUNvpxaD31BctrTfrfhE7EISil468DtzW+SexR37tK+e2SyG gUdYsFFUf4mE1iMr4wf+rlrzTfoRZRHpVOdLo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=eMyCFd1z1pB45VzUeyRSBzR5wt1qBqXh/KHGaSYIsdx4+oBJD9lt13qR+Zhbv4os2B Pjgcsmz1J90LiKMsglkOveVOv57pBJOkkjeTmY8RxdvKWt0JLfjPtJ7TWgkQM1XPbTRQ HfkidAG50qZTJQ4j8cB5N1XBCnpdcQN6KaNiE= MIME-Version: 1.0 Received: by 10.101.51.7 with SMTP id d7mr3635674ank.201.1265738994711; Tue, 09 Feb 2010 10:09:54 -0800 (PST) In-Reply-To: <4B711D44.7040509@irisa.fr> References: <14cf844b1002081907y2900c313q97ae0cb6f4c92394@mail.gmail.com> <20100209.123813.39168535.garrigue@math.nagoya-u.ac.jp> <4B711D44.7040509@irisa.fr> Date: Tue, 9 Feb 2010 12:09:54 -0600 Message-ID: <14cf844b1002091009p1a3181j793c2d6b2cdcbae5@mail.gmail.com> Subject: Re: [Caml-list] Preventing values from escaping a context From: Rich Neswold To: Tiphaine Turpin Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001636eee264287e59047f2ed341 X-Spam: no; 0.00; irisa:01 compiler:01 ocaml:01 sig:01 val:01 struct:01 mismatch:01 compiler:01 irisa:01 ocaml:01 sig:01 val:01 struct:01 'courier:98 new':98 X-Attachments: cset="UTF-8" cset="UTF-8" --001636eee264287e59047f2ed341 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Feb 9, 2010 at 2:31 AM, Tiphaine Turpin w= rote: > Jacques Garrigue a =C3=A9crit : > > From: Rich Neswold > >> My question is this: Is there a way to make the compiler reject a > function > >> parameter from returning the context parameter? > > The short answer is no. > > Types are not sufficient to prevent values from escaping. > > In ocaml, you have both functions and references. > > > There is at least a partial solution using polymorhic records or other > ways of quantifying type variables inside a type expression : If you > artificially parameterise the type context with an unused parameter (and > hide the type definition), you can then require the argument function to > be polymorphic with respect to this parameter, which should prevent it > from returning or storing its argument. > I'm not understanding you fully, sorry. I tried this: module type Test =3D sig type 'a context =3D Context of int * int val usingContext : ('a context -> 'b) -> 'b end;; module InsTest : Test =3D struct type phantom =3D unit type 'a context =3D Context of int * int let usingContext f =3D f (Context (1, 2) : phantom context) end;; But I'm getting a "Signature mismatch" error in the usingContext signature. Even trying to force the function: let usingContext (f : 'a context -> 'b) =3D f (Context (1, 2) : phantom context) causes the error (the compiler is too smart :) I've tried some minor variations, but without success. Am I even close to what you were describing? Thank you for your time, --=20 Rich Google Reader: https://www.google.com/reader/shared/rich.neswold Jabber ID: rich@neswold.homeunix.net --001636eee264287e59047f2ed341 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Feb 9, 2010 at 2:31 AM, Tiphaine Turpin <Tiphaine.Turpin@ir= isa.fr> wrote:
Jacques Garrigue a =C3=A9crit :
> From: Rich Neswold <rich.neswold@gmail.com>
>> My question is= this: Is there a way to make the compiler reject a function
>> parameter from returning the context parameter?
> The short answer is no.
> Types are not sufficient to prevent values from escaping.
> In ocaml, you have both functions and references.
>
There is at least a partial solution using polymorhic records or othe= r
ways of quantifying type variables inside a type expression : If you
artificially parameterise the type context with an unused parameter (and hide the type definition), you can then require the argument function to be polymorphic with respect to this parameter, which should prevent it
from returning or storing its argument.

I'm not understanding you fully, sorry. I tried this:
=
module type Test =3D
=C2=A0=C2=A0sig<= /font>
=C2=A0=C2=A0type 'a context =3D Context of int * int
=C2=A0=C2=A0val usingContext : ('a context -> &#= 39;b) -> 'b
=C2=A0=C2=A0end;;

=
module InsTest : Test =3D
= = =C2=A0=C2=A0struct
=C2=A0=C2=A0type phantom =3D unit
=C2=A0=C2=A0type 'a context =3D Context of int= * int
=C2=A0=C2=A0let usingContext f =3D f (Context (1= , 2) : phantom context) =C2=A0
=C2= =A0=C2=A0end;;

But I'm getting a "Signature mismatch" er= ror in the usingContext signature. Even trying to force the function:
=

let usingContext (f : 'a context -> 'b) =3D f (Context (1, = 2) : phantom context)

causes t= he error (the compiler is too smart =C2=A0:) I've tried some minor vari= ations, but without success.=C2=A0Am I even close to what you were describi= ng?

Thank you for your time,

--
Rich

Go= ogle Reader: https://www.google.com/reader/shared/rich.neswold
Jabber ID: r= ich@neswold.homeunix.net
--001636eee264287e59047f2ed341--