[Haskell-cafe] Building pattern and trying monads

L Corbijn aspergesoepje at gmail.com
Sun May 27 14:21:39 CEST 2012

Hello cafe,

I'm working on a project where the main goal of the program is
building some complex output (e.g. a Haskell function, module, etc.).
In this process there is almost always some partially finished product
on which to work. Currently I'm modelling this with a wrapper around
StateT containing the partial product but I'm having some doubts about
this approach.

On one of the projects there is some rule-based transformation which
needs to be done. The problem is with the matching and applying the
rules. The matches need to retrieve information from the monads in the
stack, and the application of a rule changes values in the stack.
However when a match fails the stack should be left *untouched* and
another rule should be tried.

The solution I've in mind depends on the stack being pure. When the
monad stack is pure a rule can be applied, returning a maybe value (or
having a MaybeT wrapper) and when returning Nothing (failed rule)
reverting the stack to it's point before applying the rule.

As I'm not quite sure about the design (nor good at software design)
I've some questions about this approach.
1. Is there a better approach then using a state monad for building
the 'products'?
2. My solution with saving/reverting monad-stacks seems quite a
hassle/hack, so is it a good approach or is there something better?

Thanks in advance,

More information about the Haskell-Cafe mailing list