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
environment idiom
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-11 (18:13)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] environment idiom
On Sat, 11 Dec 2004, Andrej Bauer wrote:
> But don't get me wrong. I definitely agree with John that having 10
> arguments to a functions sounds like too many, and something needs to be
> done in such cases. It's just that in my web application (and I suspect
> in most) I don't have 10 arguments all over the code, but more like 3 or
> 4, which is ok. Certainly different types of programs require different
> solutions.

Another solution would be to use a state monad encapsulating
the environment.  It has operators for getting and setting states.
Instead of passing all arguments from function to function "manually",
you then just need to use the monadic bind operator, which does all that
implicitly - and even purely functionally + in a statically type safe way!

See my IMP-example for a monadic interpreter, which makes
use of a state monad to pass around runtime environments:


Markus Mottl