Version française
Home     About     Download     Resources     Contact us    
Browse thread
Preventing values from escaping a context
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Rich Neswold <rich.neswold@g...>
Subject: Re: [Caml-list] Preventing values from escaping a context
On Tue, Feb 9, 2010 at 2:31 AM, Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>wrote:

> Jacques Garrigue a écrit :
> > 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 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 =
  sig
  type 'a context = Context of int * int
  val usingContext : ('a context -> 'b) -> 'b
  end;;

module InsTest : Test =
  struct
  type phantom = unit
  type 'a context = Context of int * int
  let usingContext f = 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) = 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,

-- 
Rich

Google Reader: https://www.google.com/reader/shared/rich.neswold
Jabber ID: rich@neswold.homeunix.net