
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

On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D
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'
This looks to me like the monomorphism restriction kicked in and extended defaulting is turned on, so () got inferred? If so, {-# LANGUAGE NoMonomorphismRestriction #-} at the top of the file should help. (If this is actually in ghci, then that is almost certainly what happened; many people shut off the monomorphism restriction in ghci to avoid this annoyance.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

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
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

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
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
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.

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
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
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
participants (4)
-
Brandon Allbery
-
David McBride
-
Felipe Almeida Lessa
-
Ovidiu D