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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to