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:
http://www.oefai.at/~markus/home/ocaml_sources.html
Regards,
Markus
--
Markus Mottl http://www.oefai.at/~markus markus@oefai.at