Hi all,<br>
<br>
I&#39;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 -&gt; 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&#39;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&#39;t make a derived instance of `Monad (Filter e)&#39;</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&#39;</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&#39;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)&#39;</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&#39;</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&#39;t figure out how I&#39;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&#39; 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&#39;m not sure that&#39;s appropriate for a digital filter.<br>
<br>
Thanks,<br>
-db<br>