[Haskell-cafe] Trouble using State Monad.
dmbarbour at gmail.com
Mon Oct 10 05:16:40 CEST 2011
On Sun, Oct 9, 2011 at 7:57 PM, Captain Freako <capn.freako at gmail.com>wrote:
> 21 applyFilter :: Filter e a -> FilterState -> a -> (Either e a,
> 22 applyFilter f s x = runState (runEitherT (runFilter f)) s
> I still don't understand how I'm supposed to feed the input, `x', into the
In 'Filter e a', a is an output type, not an input type. If you want inputs,
you'll need constructors of the form (a -> Filter e b).
This might be closer to what you're looking for:
applyFilter :: FilterState -> (a -> Filter e b) -> a -> (Either e b,
applyFilter s f x = runState (runEitherT (runFilter (f x))) s
The burden of receiving input is then shifted to the functions that create
If you really want the input type to be part of the Filter type definition,
you'll need to use arrows instead of monads.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe