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')<br>import Data.Enumerator hiding (foldl')<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) >>=<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) >>= print<br>-- where<br>-- enum = foldl' ($=)<br>-- (enumList 5 [1..])<br>-- [ EL.isolate 100<br>
-- , EL.filter ((==0) . (`mod` 2))<br>-- ]<br><br>main :: IO ()<br>main = run (enum $$ it) >>= 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;">> :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 =></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;"> -> Enumeratee ao ai m b</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> -> 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;">> :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 =></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Enumeratee ao ai m b -> Iteratee ai m b -> 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'm really curious to know what is going on with the types when using the ($=) operator, I'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"><<a href="mailto:romanandreg@gmail.com">romanandreg@gmail.com</a>></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'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'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')<br>import Data.Enumerator hiding (foldl')<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) >>= <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) >>= print<br>-- where<br>-- enum = foldl' ($=) <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't compile, I'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'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"><<a href="mailto:conrad@metadecks.org" target="_blank">conrad@metadecks.org</a>></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 <<a href="mailto:romanandreg@gmail.com" target="_blank">romanandreg@gmail.com</a>>:<br>
<div><div></div><div>> Hey guys,<br>
><br>
> Right now I'm facing with a type problem that is really nasty, I want to<br>
> compose a list of enumeratees using the ($=) operator to create a new<br>
> enumerator. Whenever I'm trying to use the foldx function in conjunction<br>
> with ($=) I get this error:<br>
><br>
>> :t foldr ($=)<br>
><br>
> <interactive>:1:7:<br>
> Occurs check: cannot construct the infinite type:<br>
> b0 = Step ao0 m0 b0<br>
> Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumerator ao0 m0 b0<br>
> In the first argument of `foldr', namely `($=)'<br>
> In the expression: foldr ($=)<br>
><br>
>> :t Prelude.foldl ($=)<br>
><br>
> <interactive>:1:15:<br>
> Occurs check: cannot construct the infinite type:<br>
> b0 = Step ao0 m0 b0<br>
> Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumerator ao0 m0 b0<br>
> In the first argument of `Prelude.foldl', namely `($=)'<br>
> In the expression: Prelude.foldl ($=)<br>
><br>
> <interactive>:1:15:<br>
> Occurs check: cannot construct the infinite type:<br>
> b0 = Step ao0 m0 b0<br>
> Expected type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> Actual type: Enumerator ao0 m0 (Step ao0 m0 b0)<br>
> -> Enumeratee ao0 ao0 m0 b0<br>
> -> Enumerator ao0 m0 b0<br>
> In the first argument of `Prelude.foldl', namely `($=)'<br>
> In the expression: Prelude.foldl ($=)<br>
><br>
> Obviously there is something I don't quite understand about the ($=) (=$)<br>
> 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>