English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2010-02-11 (15:17)
From: rossberg@m...
Subject: Re: [Caml-list] Preventing values from escaping a context
"Alexey Rodriguez" <mrchebas@gmail.com> wrote:
>>> But for this you need support from the type system (rank-2 universal
>>> quantification).
>> FWIW, OCaml can express that, but it doesn't help the problem.
> Andreas, I'd be interested in seeing such encodings. Any pointers?

There are currently two ways to express that in OCaml, either through
polymorphic record fields or through polymorphic object methods. For the
former, consider:

  type f_arg = {it : 'a. 'a -> 'a}
  let f {it = g} = (g 5, g true)

  f {it = fun x -> x}

One caveat is that the value restriction can byte you, especially if you
try to encode s.th like monads, but that's a somewhat separate issue.