[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-beginners
Subject:    Re: [Haskell-beginners] Conduit composition
From:       Ovidiu D <ovidiudeac () gmail ! com>
Date:       2013-04-10 5:52:46
Message-ID: CAKVsE7toz-a2p4LgufyrYmaOxK=ySA=ic-ghmPz1oJDP+vXNjg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


That makes a lot of sense. Thanks!


On Wed, Apr 10, 2013 at 2:49 AM, Felipe Almeida Lessa <
felipe.lessa@gmail.com> wrote:

> Complementing David McBride's answer, what misled you is probably the
> precedence of the operators.  Your original expression is the same as:
>
>   main =
>     (((Conduit.sourceList [1..14]
>     $= Conduit.map show)
>     $= Conduit.iterM putStrLn)
>     $= Conduit.iterM putStrLn)
>     $$ Conduit.sinkNull
>
> Cheers,
>
> On Tue, Apr 9, 2013 at 7:54 PM, David McBride <toad3k@gmail.com> wrote:
> > The reason is because the operator $= puts together a source and a
> conduit
> > and returns a new source.
> >
> > The operator =$= is used to combine two conduits into another conduit.
> >
> > With $= if you try to put two conduits together, the underlying types
> just
> > won't match up.  They don't match up specifically to tell you that you
> are
> > not quite doing it correctly.  It is trying to match the first argument
> to a
> > source, which has its input type restricted to ().  Since you have a
> string
> > there, then it complains.
> >
> > So try display = CL.iterM putStrLn =$= CL.iterM putStrLn  which does
> exactly
> > what you were looking for.
> >
> >
> > On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D <ovidiudeac@gmail.com> wrote:
> >>
> >> Given the following works as expected (i.e. prints the value twice):
> >>
> >> main =
> >>     Conduit.sourceList [1..14]
> >>     $= Conduit.map show
> >>     $= Conduit.iterM putStrLn
> >>     $= Conduit.iterM putStrLn
> >>     $$ Conduit.sinkNull
> >>
> >> I would expect the following to work as well:
> >> main =
> >>     Conduit.sourceList [1..14]
> >>     $= Conduit.map show
> >>     $= display
> >>     $$ Conduit.sinkNull
> >>
> >> display = Conduit.iterM putStrLn $= Conduit.iterM putStrLn
> >>
> >> ...but I get the compilation error:
> >> Couldn't match expected type `String' with actual type `()'
> >>     Expected type: Conduit.Conduit String m0 a0
> >>       Actual type: Conduit.Source IO ()
> >>     In the second argument of `($=)', namely `display'
> >>     In the first argument of `($$)', namely
> >>       `Conduit.sourceList [1 .. 14] $= Conduit.map show $= display'
> >>
> >> I don't understand why the type of display is inferred to a
> >> Conduit.Source. Can somebody please explain?
> >>
> >> What I want is to have readable names for certain segments in my pipe.
> Is
> >> that possible?
> >>
> >> Thanks,
> >> ovidiu
> >>
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> Beginners@haskell.org
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
> --
> Felipe.
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>

[Attachment #5 (text/html)]

<div dir="ltr">That makes a lot of sense. Thanks!<br></div><div \
class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 10, 2013 at 2:49 AM, \
Felipe Almeida Lessa <span dir="ltr">&lt;<a href="mailto:felipe.lessa@gmail.com" \
target="_blank">felipe.lessa@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">Complementing David McBride&#39;s answer, what misled you is \
probably the<br> precedence of the operators.  Your original expression is the same \
as:<br> <br>
  main =<br>
    (((Conduit.sourceList [1..14]<br>
    $= Conduit.map show)<br>
    $= Conduit.iterM putStrLn)<br>
    $= Conduit.iterM putStrLn)<br>
    $$ Conduit.sinkNull<br>
<br>
Cheers,<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Apr 9, 2013 at 7:54 PM, David McBride &lt;<a \
href="mailto:toad3k@gmail.com">toad3k@gmail.com</a>&gt; wrote:<br> &gt; The reason is \
because the operator $= puts together a source and a conduit<br> &gt; and returns a \
new source.<br> &gt;<br>
&gt; The operator =$= is used to combine two conduits into another conduit.<br>
&gt;<br>
&gt; With $= if you try to put two conduits together, the underlying types just<br>
&gt; won&#39;t match up.  They don&#39;t match up specifically to tell you that you \
are<br> &gt; not quite doing it correctly.  It is trying to match the first argument \
to a<br> &gt; source, which has its input type restricted to ().  Since you have a \
string<br> &gt; there, then it complains.<br>
&gt;<br>
&gt; So try display = CL.iterM putStrLn =$= CL.iterM putStrLn  which does exactly<br>
&gt; what you were looking for.<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D &lt;<a \
href="mailto:ovidiudeac@gmail.com">ovidiudeac@gmail.com</a>&gt; wrote:<br> \
&gt;&gt;<br> &gt;&gt; Given the following works as expected (i.e. prints the value \
twice):<br> &gt;&gt;<br>
&gt;&gt; main =<br>
&gt;&gt;     Conduit.sourceList [1..14]<br>
&gt;&gt;     $= Conduit.map show<br>
&gt;&gt;     $= Conduit.iterM putStrLn<br>
&gt;&gt;     $= Conduit.iterM putStrLn<br>
&gt;&gt;     $$ Conduit.sinkNull<br>
&gt;&gt;<br>
&gt;&gt; I would expect the following to work as well:<br>
&gt;&gt; main =<br>
&gt;&gt;     Conduit.sourceList [1..14]<br>
&gt;&gt;     $= Conduit.map show<br>
&gt;&gt;     $= display<br>
&gt;&gt;     $$ Conduit.sinkNull<br>
&gt;&gt;<br>
&gt;&gt; display = Conduit.iterM putStrLn $= Conduit.iterM putStrLn<br>
&gt;&gt;<br>
&gt;&gt; ...but I get the compilation error:<br>
&gt;&gt; Couldn&#39;t match expected type `String&#39; with actual type `()&#39;<br>
&gt;&gt;     Expected type: Conduit.Conduit String m0 a0<br>
&gt;&gt;       Actual type: Conduit.Source IO ()<br>
&gt;&gt;     In the second argument of `($=)&#39;, namely `display&#39;<br>
&gt;&gt;     In the first argument of `($$)&#39;, namely<br>
&gt;&gt;       `Conduit.sourceList [1 .. 14] $= Conduit.map show $= display&#39;<br>
&gt;&gt;<br>
&gt;&gt; I don&#39;t understand why the type of display is inferred to a<br>
&gt;&gt; Conduit.Source. Can somebody please explain?<br>
&gt;&gt;<br>
&gt;&gt; What I want is to have readable names for certain segments in my pipe. \
Is<br> &gt;&gt; that possible?<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; ovidiu<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Beginners mailing list<br>
&gt;&gt; <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/beginners" \
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br> \
&gt;&gt;<br> &gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Beginners mailing list<br>
&gt; <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/beginners" \
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br> &gt;<br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Felipe.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" \
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br> \
</div></div></blockquote></div><br></div>



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic