[Haskell-cafe] Trouble using State Monad.
Captain Freako
capn.freako at gmail.com
Mon Oct 10 04:57:12 CEST 2011
Hi David,
Thanks for the reply.
In trying to follow your advice, I arrived at this code:
17 newtype Filter e a = F {
18 runFilter :: EitherT e (State FilterState) a
19 } deriving (Monad, MonadState FilterState)
20
21 applyFilter :: Filter e a -> FilterState -> a -> (Either e a,
FilterState)
22 applyFilter f s x = runState (runEitherT (runFilter f)) s
which compiles ok, but I don't know where to put the `x' on the right side
of the `=' in line 22. That is, I still don't understand how I'm supposed to
feed the input, `x', into the filter.
Thanks,
-db
On Sat, Oct 8, 2011 at 5:27 PM, David Barbour <dmbarbour at gmail.com> wrote:
>
>
> On Sat, Oct 8, 2011 at 4:28 PM, Captain Freako <capn.freako at gmail.com>wrote:
>
>>
>> 17 newtype Filter e a = F {
>> * 18 runFilter :: EitherT e (State FilterState) a
>> ** * 19 } deriving (Monad, MonadState FilterState)
>>
>> it compiles, but I can't figure out how I'd feed the input to the filter,
>> in that case.
>>
>
> Input to Filter would be modeled with: 'a -> Filter e b'.
>
> I would rename your 'runFilter' to 'unFilter', then define a function
> 'runFilter' accepting an initial FilterState.
>
> Regards,
>
> - db
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111009/baa6229b/attachment.htm>
More information about the Haskell-Cafe
mailing list