How to construct large and fast Haskell programs ?
Magnus Lindberg
f98mali@dd.chalmers.se
Tue, 06 May 2003 08:59:41 +0200
Hi, I have some Haskell questions !
First, thank you Derek Elkins for your help regarding monadic
transformers and functinal dependencies.
Now, a(nother) question. When I create large programs in Haskell I
tend to end up with a lot of variables which I pass around in monads.
I use different kinds of (state) monads with different sets of
variables for different tasks in the program. I wonder if it is it
good to use many different monades? E.g. one monad for each big task
in the program.
All my monads have a function `randf' which operates on a StdGen (the
StdGen is part of the monad state). I have rewritten the `randf'
function for each monad. I also pass the StdGen explicitely between
the different monads. I don't want to rewrite `randf' and pass around
the StdGen. Is there any solution for this problem?
Perhaps monad transformers could be to some help here. Perhaps one
could create a state monad with a StdGen as state and also a `randf'
function. Then the other monads could be buildt upon this state monad.
Would this be a solution?
However, if it would be a solution I wouldn't use it because I want my
program to be fast (it should do "heavy" computations). If I use monad
transformers I imagine that each "monadic instruction" will take
longer time since both the StdGen monad and the monad built on the
StdGen monad will be involved in the "monadic instruction". Every row
in my program would then become a bit slower which I don't like -
especially not since inner loops are written in the monad built on the
StdGen monad. Am I right - will my code be much slower if I use monad
transformers?
Would you recommend writing functions one wants to be fast with as few
monads as possible, e.g. only using the IO monad or no monad at all?
One could then pass around parameters (which could have been part of a
state) as arguments between different functions. This would eliminate
the (CPU consuming?) implicit passing of a state between all "monadic
instructions".
Keen regards, Magnus Lindberg