[Haskell-cafe] Trouble using State Monad.
Captain Freako
capn.freako at gmail.com
Sun Oct 9 01:28:34 CEST 2011
Hi all,
I'm trying to use the State Monad to help implement a digital filter:
17 newtype Filter e a = F {
18 runFilter :: a -> EitherT e (State FilterState) a
19 } deriving (Monad, MonadState FilterState)
but I'm getting these compiler errors:
Filter.hs:19:14:
Can't make a derived instance of `Monad (Filter e)'
(even with cunning newtype deriving):
cannot eta-reduce the representation type enough
In the newtype declaration for `Filter'
Filter.hs:19:21:
Can't make a derived instance of
`MonadState FilterState (Filter e)'
(even with cunning newtype deriving):
cannot eta-reduce the representation type enough
In the newtype declaration for `Filter'
If I change the code to this:
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.
In comparing this to the tricks used in constructing the State Monad based
version of the `Parser' type,
I notice that Parser gets around this issue, by having the input (i.e. -
input stream) be a part of the initial state,
but I'm not sure that's appropriate for a digital filter.
Thanks,
-db
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111008/fc02d553/attachment.htm>
More information about the Haskell-Cafe
mailing list