Hi all,<br>
<br>
I'm trying to use the State Monad to help implement a digital filter:<br>
<br>
<span style="font-family: courier new,monospace;"> 17 newtype Filter e a = F {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 18 runFilter :: a -> EitherT e (State FilterState) a</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 19 } deriving (Monad, MonadState FilterState)</span><br style="font-family: courier new,monospace;">
<br>
but I'm getting these compiler errors:<br>
<br>
<span style="font-family: courier new,monospace;">Filter.hs:19:14:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Can't make a derived instance of `Monad (Filter e)'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (even with cunning newtype deriving):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cannot eta-reduce the representation type enough</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> In the newtype declaration for `Filter'</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Filter.hs:19:21:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Can't make a derived instance of</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> `MonadState FilterState (Filter e)'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (even with cunning newtype deriving):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cannot eta-reduce the representation type enough</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> In the newtype declaration for `Filter'</span><br style="font-family: courier new,monospace;">
<br>
If I change the code to this:<br>
<br>
<span style="font-family: courier new,monospace;"> 17 newtype Filter e a = F {</span><br style="font-family: courier new,monospace;">
<b><span style="font-family: courier new,monospace;">
18 runFilter :: EitherT e (State FilterState) a</span><br style="font-family: courier new,monospace;">
</b><span style="font-family: courier new,monospace;"><b>
</b> 19 } deriving (Monad, MonadState FilterState)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
</span><br>
it compiles, but I can't figure out how I'd feed the input to the filter, in that case.<br>
<br>
In comparing this to the tricks used in constructing the State Monad based version of the `Parser' type,<br>
I notice that Parser gets around this issue, by having the input (i.e. - input stream) be a part of the initial state,<br>
but I'm not sure that's appropriate for a digital filter.<br>
<br>
Thanks,<br>
-db<br>