Hello guys,<br><br>After some playing around trying to compose enumerators, I went through a different approach and tried instead to compose through Iteratees.<br><br>The following code does compile correctly<br><span style="font-family: courier new,monospace;"><br>

import Data.List (foldl&#39;)<br>import Data.Enumerator hiding (foldl&#39;)<br>import qualified Data.Enumerator.List as EL<br><br>-- This is what I orginally have<br>--main :: IO ()<br>--main = run_ (((enumList 5 [1..] $=<br>

--               EL.isolate 100) $=<br>--               EL.filter ((== 0) . (`mod` 2))) $$<br>--               EL.consume) &gt;&gt;=<br>--       print  <br>              <br>-- This is what I want and for some reason is not<br>

-- compiling (infinite type error)<br>--main2 :: IO ()<br>--main2 = run (enum $$ EL.consume) &gt;&gt;= print<br>-- where<br>--   enum = foldl&#39; ($=)<br>--                 (enumList 5 [1..])<br>--                 [ EL.isolate 100<br>

--                 , EL.filter ((==0) . (`mod` 2))<br>--                 ]<br><br>main :: IO ()<br>main = run (enum $$ it) &gt;&gt;= print<br> where<br>   enum = enumList 5 [1..]<br>   it   = foldr (=$)<br>                EL.consume<br>

                [ EL.isolate 100<br>                , EL.filter ((==0) . (`mod` 2))<br>                ]<br><br><br></span>It seems the (=$) operator behaves in a better way than the ($=) operator... When I check the signatures of both functions<br>

<br><span style="font-family: courier new,monospace;">&gt; :t ($=) </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">($=)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  :: Monad m =&gt;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     Enumerator ao m (Step ai m b)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     -&gt; Enumeratee ao ai m b</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     -&gt; Enumerator ai m b</span><br>

<br>The original enumerator of type (Enumerator a m b) gets transformed to (Enumerator ao m (Step ai m b)), how this works is beyond me. <br><br>When checking the type of (=$)<br><span style="font-family: courier new,monospace;">&gt; :t ($=)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">(=$)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  :: Monad m =&gt;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     Enumeratee ao ai m b -&gt; Iteratee ai m b -&gt; Iteratee ao m b</span><br style="font-family: courier new,monospace;"><br>Returns something with more sense, when using an Iteratee as a base of a foldr of enumeratees, the response for the next one will always be an <span style="font-family: courier new,monospace;">Iteratee ao m b</span>, the return type of the Iteratee is not changed with a Step type suddenly like in ($=).<br>

<br>I solved my problem, however I&#39;m really curious to know what is going on with the types when using the ($=) operator, I&#39;m going to investigate on my part and try to come with some clear explanation, however if anyone can chime in and give us some insights, they are more than welcome.<br>

<br>Cheers.<br><br>Roman.-<br><br><div class="gmail_quote">2011/10/4 Román González <span dir="ltr">&lt;<a href="mailto:romanandreg@gmail.com">romanandreg@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hello Conrad,<br><br><br>Thanks for taking the time to answer back. Actually I don&#39;t want to do anything fancy, I just want to compose a list of Enumeratees together into an Enumerator, using the same type for both <span style="font-family:courier new,monospace">ao</span> and <span style="font-family:courier new,monospace">ai</span>, I suspect it doesn&#39;t matter what the type of this ao and ai are, I would obtain the same error using this simpler example:<br>


<br><span style="font-family:courier new,monospace">module Main where<br><br>import Data.List (foldl&#39;)<br>import Data.Enumerator hiding (foldl&#39;)<br>import qualified Data.Enumerator.List as EL<br><br>-- This is what I orginally have<br>


main :: IO ()<br>main = run_ (((enumList 5 [1..] $=<br>               EL.isolate 100) $=<br>               EL.filter ((== 0) . (`mod` 2))) $$<br>               EL.consume) &gt;&gt;= <br>       print   <br>               <br>


-- This is what I want and for some reason is not <br>-- compiling (infinite type error)<br>--main2 :: IO ()<br>--main2 = run (enum $$ EL.consume) &gt;&gt;= print<br>-- where<br>--   enum = foldl&#39; ($=) <br>--                 (enumList 5 [1..]) <br>


--                 [ EL.isolate 100<br>--                 , EL.filter ((==0) . (`mod` 2))<br>--                 ]<br></span><br><br><br>For some complicated type logic, main2 won&#39;t compile, I&#39;m trying to figure out a way to actually do this. The reason why I want to do the composition through list is because I&#39;m mapping input parameters (from System.Environment.getArgs) to a list of Enumeratees, and I want to compose them dynamically.<br>


<br>Hope this helps.<br><br>Roman.- <br><div><div></div><div class="h5"><br><div class="gmail_quote">2011/10/3 Conrad Parker <span dir="ltr">&lt;<a href="mailto:conrad@metadecks.org" target="_blank">conrad@metadecks.org</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2011/10/4 Román González &lt;<a href="mailto:romanandreg@gmail.com" target="_blank">romanandreg@gmail.com</a>&gt;:<br>
<div><div></div><div>&gt; Hey guys,<br>
&gt;<br>
&gt; Right now I&#39;m facing with a type problem that is really nasty, I want to<br>
&gt; compose a list of enumeratees using the ($=) operator to create a new<br>
&gt; enumerator.  Whenever I&#39;m trying to use the foldx function in conjunction<br>
&gt; with ($=) I get this error:<br>
&gt;<br>
&gt;&gt; :t foldr ($=)<br>
&gt;<br>
&gt; &lt;interactive&gt;:1:7:<br>
&gt;     Occurs check: cannot construct the infinite type:<br>
&gt;       b0 = Step ao0 m0 b0<br>
&gt;     Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;       Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumerator ao0 m0 b0<br>
&gt;     In the first argument of `foldr&#39;, namely `($=)&#39;<br>
&gt;     In the expression: foldr ($=)<br>
&gt;<br>
&gt;&gt; :t Prelude.foldl ($=)<br>
&gt;<br>
&gt; &lt;interactive&gt;:1:15:<br>
&gt;     Occurs check: cannot construct the infinite type:<br>
&gt;       b0 = Step ao0 m0 b0<br>
&gt;     Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;       Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumerator ao0 m0 b0<br>
&gt;     In the first argument of `Prelude.foldl&#39;, namely `($=)&#39;<br>
&gt;     In the expression: Prelude.foldl ($=)<br>
&gt;<br>
&gt; &lt;interactive&gt;:1:15:<br>
&gt;     Occurs check: cannot construct the infinite type:<br>
&gt;       b0 = Step ao0 m0 b0<br>
&gt;     Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;       Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
&gt;                    -&gt; Enumeratee ao0 ao0 m0 b0<br>
&gt;                    -&gt; Enumerator ao0 m0 b0<br>
&gt;     In the first argument of `Prelude.foldl&#39;, namely `($=)&#39;<br>
&gt;     In the expression: Prelude.foldl ($=)<br>
&gt;<br>
&gt; Obviously there is something I don&#39;t quite understand about the ($=) (=$)<br>
&gt; functions, how can one compose a list of enumeratees, is it even possible?<br>
<br>
</div></div>Hi,<br>
<br>
what are you trying to actually do, ie. what kind of data are you<br>
trying to transform, what are the inputs and outputs of each<br>
enumeratee?<br>
<br>
are you trying to feed the output of the first enumeratee into the<br>
input of the second, and so on? or are you trying to run them all in<br>
parallel?<br>
<font color="#888888"><br>
Conrad.<br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>