Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 (10:39)
From: Alexey Rodriguez <mrchebas@g...>
Subject: Re: [Caml-list] Preventing values from escaping a context
On Tue, Feb 9, 2010 at 4:59 AM, Yaron Minsky <> wrote:
> I don't know that monads solve your problem here, but monads are a perfectly
> reasonable idiom in OCaml.  You won't find them in the standard library
> because the standard library is very conservative.  But you will find them
> in Jane Street's Core library, and we use them reasonably often.  I think
> there's no reason to avoid monads in OCaml (although obviously there's not
> much to be gained by using them for vanilla effects, as is done in Haskell.)

This is interesting. We have been considering using monads where I
work but we worry about possible performance problems. Have you
experienced reduced performance? Also, do you have a guideline on when
to use them? We are thinking of using monads in a DSL, but only to
build values (think of some kind of compilation) that can later be
efficiently inspected.

On whether monads can solve the problem in this thread, yes they can.
But for this you need support from the type system (rank-2 universal
quantification). This is what Haskell does with the ST monad. The
compiler detects the value leak and aborts compilation with a type
error. If you are interested in a reference I can dig it up later.