Your filter type isn&#39;t a Monad.<br><br>In particular<br><br>bind :: (a -&gt; EitherT e (State FilterState) a) -&gt; (a -&gt; b -&gt; EitherT e (State FilterState) b) -&gt; b -&gt; EitherT e (State FilterState) b<br><br>
can&#39;t be implemented, as you have no place to grab an &#39;a&#39; to pass to the initial computation.<br><br>If you fix the input type, you can do<br><br>newtype Filter r e a = F {<br>    runFilter :: r -&gt; EitherT e (State FilterState) a<br>
}<br><br>which is isomorphic to<br><br>newtype Filter r e a = F {<br>
    runFilter :: ReaderT r (EitherT e (State FilterState)) a<br>
}<br><br>which newtype deriving will be able to deal with easily.<br><br>  -- ryan<br>
<br>
<br><div class="gmail_quote">On Sat, Oct 8, 2011 at 4:28 PM, Captain Freako <span dir="ltr">&lt;<a href="mailto:capn.freako@gmail.com">capn.freako@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>