[Haskell-cafe] Trouble using State Monad.

David Barbour 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,
> FilterState)
>  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
> filter.

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
'Filter' operations.

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...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111009/934a3f0b/attachment.htm>

More information about the Haskell-Cafe mailing list