[Haskell-beginners] Architecture and monads

Amy de Buitléir amy at nualeargais.ie
Tue Dec 7 00:18:21 CET 2010


Until recently, the choice of whether or not to use monads was easy. I
didn't understand them, so I avoided them! But now that I think I
understand enough to begin to use them, I have a different problem: I
don't have the experience to know when using them is a good idea, and
when it's overkill. This is my first serious Haskell project, and I
would appreciate any advice.

Here's the scenario: I'm developing a virtual world with alife
creatures. At one extreme, I guess I could use the State monad for
everything that has state, right down to the neurons in their brains.
(I assume that would be overkill.) At the other extreme, I could do
without the State monad altogether, and just have functions that take
a creature, let it have an experience, and return a new creature. I
guess somewhere in-between there's a happy medium. Perhaps I should us
the State monad for the creatures, but not for anything lower-level
than that. Or maybe use it for the creatures and their brains. One
issue that complicates things slightly is that a *lot* of the
processing I'm doing requires random numbers. The neurons don't
require any randomness, but the brain as a whole does. And
reproduction requires randomness down at the DNA level. The code
works, but I feel it's a bit messy because of needing randomness in so
many places, and I'd like to clean up the design a bit.

Generally speaking, is it best to go for the "bon-bon" approach, with
a pure functional core, and a monadic layer on the outside?



More information about the Beginners mailing list