Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  </>? Was: doesFileExist cannot get ~/blah_blah right
      (Daniel Trstenjak)
   2.  Conduit composition (Ovidiu D)
   3. Re:  Conduit composition (Brandon Allbery)
   4. Re:  Conduit composition (David McBride)
   5. Re:  Conduit composition (Felipe Almeida Lessa)
   6. Re:  </>? Was: doesFileExist cannot get ~/blah_blah right
      (Brent Yorgey)


----------------------------------------------------------------------

Message: 1
Date: Tue, 9 Apr 2013 18:29:53 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] </>? Was: doesFileExist cannot get
        ~/blah_blah right
To: [email protected]
Message-ID: <20130409162953.GA19527@machine>
Content-Type: text/plain; charset=us-ascii


Hi Tommy,

On Tue, Apr 09, 2013 at 11:15:01AM -0500, Tommy M. McGuire wrote:
> Wait, what? Where'd "</>" come from?

hoogle or hayoo are great for answering such question, just try searching for 
</> .

It's from: http://hackage.haskell.org/package/filepath


Greetings,
Daniel



------------------------------

Message: 2
Date: Wed, 10 Apr 2013 01:34:40 +0300
From: Ovidiu D <[email protected]>
Subject: [Haskell-beginners] Conduit composition
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAKVsE7vN-Yio5dnV=tJLb8vaEbfkqN=hpcooye67ns6bm6g...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130410/27069046/attachment-0001.htm>

------------------------------

Message: 3
Date: Tue, 9 Apr 2013 18:42:11 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Conduit composition
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAKFCL4XKG25rn29=eNjovY=XOGXUaFxQD7ZLFJPCB+=vmo1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D <[email protected]> wrote:

> 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
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130409/dd255c95/attachment-0001.htm>

------------------------------

Message: 4
Date: Tue, 9 Apr 2013 18:54:10 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Conduit composition
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAN+Tr43=zUGqjyqsh7G4VJEJube4_OiVVD=gMxeRQro=xuz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130409/f6727d64/attachment-0001.htm>

------------------------------

Message: 5
Date: Tue, 9 Apr 2013 20:49:53 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Conduit composition
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CANd=oghq-navjm7c1c9d6wirmes9cw0dtsu-fbcs99mrv2c...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

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 <[email protected]> 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 <[email protected]> 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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Felipe.



------------------------------

Message: 6
Date: Tue, 9 Apr 2013 20:06:23 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] </>? Was: doesFileExist cannot get
        ~/blah_blah right
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, Apr 09, 2013 at 12:25:10PM -0400, David McBride wrote:
> There is a package system-filepath
> http://hackage.haskell.org/package/system-filepath which fixes a lot of
> quibbles people have with the way filepaths are implemented in haskell.
> There are apparently a lot of problems with using strings as filepaths,
> like the fact that they are slow, that they have encoding issues, and that
> people cannot make a path that is system agnostic.
> 
> So the </> operator in that library just joins two filepaths together with
> the correct slash.

This is all true, though using system-filepath is still annoying to
use because it doesn't play well with everything else in the Haskell
ecosystem.  However, I was not referring to the (</>) in
system-filepath but rather the one in the standard 'filepath' package.

-Brent



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 58, Issue 20
*****************************************

Reply via email to