[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"><<a href="mailto:felipe.lessa@gmail.com" \
target="_blank">felipe.lessa@gmail.com</a>></span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Complementing David McBride'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 <<a \
href="mailto:toad3k@gmail.com">toad3k@gmail.com</a>> wrote:<br> > The reason is \
because the operator $= puts together a source and a conduit<br> > and returns a \
new source.<br> ><br>
> The operator =$= is used to combine two conduits into another conduit.<br>
><br>
> With $= if you try to put two conduits together, the underlying types just<br>
> won't match up. They don't match up specifically to tell you that you \
are<br> > not quite doing it correctly. It is trying to match the first argument \
to a<br> > source, which has its input type restricted to (). Since you have a \
string<br> > there, then it complains.<br>
><br>
> So try display = CL.iterM putStrLn =$= CL.iterM putStrLn which does exactly<br>
> what you were looking for.<br>
><br>
><br>
> On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D <<a \
href="mailto:ovidiudeac@gmail.com">ovidiudeac@gmail.com</a>> wrote:<br> \
>><br> >> Given the following works as expected (i.e. prints the value \
twice):<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>
>> I would expect the following to work as well:<br>
>> main =<br>
>> Conduit.sourceList [1..14]<br>
>> $= Conduit.map show<br>
>> $= display<br>
>> $$ Conduit.sinkNull<br>
>><br>
>> display = Conduit.iterM putStrLn $= Conduit.iterM putStrLn<br>
>><br>
>> ...but I get the compilation error:<br>
>> Couldn't match expected type `String' with actual type `()'<br>
>> Expected type: Conduit.Conduit String m0 a0<br>
>> Actual type: Conduit.Source IO ()<br>
>> In the second argument of `($=)', namely `display'<br>
>> In the first argument of `($$)', namely<br>
>> `Conduit.sourceList [1 .. 14] $= Conduit.map show $= display'<br>
>><br>
>> I don't understand why the type of display is inferred to a<br>
>> Conduit.Source. Can somebody please explain?<br>
>><br>
>> What I want is to have readable names for certain segments in my pipe. \
Is<br> >> that possible?<br>
>><br>
>> Thanks,<br>
>> ovidiu<br>
>><br>
>><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> \
>><br> ><br>
><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> ><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