Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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:  IO and ghci (Mike Houghton)
   2.  What's the mean of >>= (???)
   3. Re:  What's the mean of >>= (Alexey Shmalko)
   4. Re:  What's the mean of >>= (???)


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

Message: 1
Date: Sun, 19 Apr 2015 13:28:36 +0100
From: Mike Houghton <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] IO and ghci
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Thank you Friedrich, that really does help.
At some point I became confused as I?m *sure* that I tried file <- readFile 
?poem.txt? in ghci and it didn?t work! Clearly it does. :)
Thanks again.

Mike





> On 19 Apr 2015, at 11:03, Friedrich Wiemer <[email protected]> wrote:
> 
> Hi Mike
> as you perhaps have noticed, you use slightly different notations here:
> 
>> file <- readFile "poem.txt"
> 
>> let f = readFile ?poem.txt?     
> 
> You can run both versions in ghci, and if you take a look at the type
> signatures:
> ?> file <- readFile "poem.txt"
> ?> :t file
> file :: String
> 
> ?> let f = readFile "poem.txt"
> ?> :t f
> f :: IO String
> 
> You'll notice that f has type "IO String", whereas file only has type
> "String".
> 
> So, to answer your second question: you can progress by using the "<-"
> notation, as in your haskell source code.
> 
> To answer the first one: I'm not sure about ghci command prompt, but I
> would expect, that it is equivalent to "main = do ...".
> That is, the type error you got, is not due to ghci and main = do are
> different, but because you used to different types.
> 
> To understand the "<-" notation, the example from Learn you a Haskell
> was quite good for me:
> Try to see types like "IO String" as an action or box, which can result
> in a string. You can take the inner type out of the box, by using "<-".
> 
> Hope that helps,
> 
> cheers,
> Friedrich
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Message: 2
Date: Sun, 19 Apr 2015 16:33:08 -0700
From: ??? <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] What's the mean of >>=
Message-ID: <[email protected]>
Content-Type: text/plain; charset="euc-kr"

It could be stupid question because i'm very beginner of haskell.
 
I found strange literals when i read haskell code.
Does anybody explan what the mean of >>= below ocode ? And additionally, What 
is mean of >> itself?
 
putStrLn' [] = putChar '\n'
putStrLn' xs - putStr' xs >>= \ x -> putChar '\n'
 
putStr' [] = return ()
putStr' (x : xs) = putChar x >> putStr' n
 
(because of i18n problem, back slash literal could be shown as '\')
 
Thank you in advance
Myung Shin Kim
 
                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150419/20447a55/attachment-0001.html>

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

Message: 3
Date: Mon, 20 Apr 2015 02:51:33 +0300
From: Alexey Shmalko <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What's the mean of >>=
Message-ID:
        <CAFC2PC6q1baULRyC6QwiZ7uf6asV++mj9BteT=np4oqctgn...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello!

>>= and >> are methods of Monad typeclass. Their meaning may be very different 
>>depending on the actual type. For IO >>= composes a new IO action which is, 
>>when executed, executes left action first and then passes its result to the 
>>right function.

So you can read
putStr' xs >>= \ x -> putChar '\n'
as "Execute action putStr' xs, then pass its result to \x -> putChar '\n'".

Many times the result of previous action is not used (as in above
example), so there is >> which is like >>= but ignores the result of
first action.
It's something like
x >> y = x >>= (\_ -> y)

So putStr' xs >> putChar '\n' is the same as putStr' xs >>= \ x -> putChar '\n'

This code can be rewritten in the do-notation as:
do
    putStr' xs
    putChar '\n'

To summarize, for IO, >>= and >> are used to sequence actions.

Best regards,
Alexey Shmalko

On Mon, Apr 20, 2015 at 2:33 AM, ??? <[email protected]> wrote:
> It could be stupid question because i'm very beginner of haskell.
>
> I found strange literals when i read haskell code.
> Does anybody explan what the mean of >>= below ocode ? And additionally,
> What is mean of >> itself?
>
> putStrLn' [] = putChar '\n'
> putStrLn' xs - putStr' xs >>= \ x -> putChar '\n'
>
> putStr' [] = return ()
> putStr' (x : xs) = putChar x >> putStr' n
>
> (because of i18n problem, back slash literal could be shown as '\')
>
> Thank you in advance
> Myung Shin Kim
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


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

Message: 4
Date: Sun, 19 Apr 2015 17:13:48 -0700
From: ??? <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] What's the mean of >>=
Message-ID: <[email protected]>
Content-Type: text/plain; charset="euc-kr"

I really appeciate your answer.
 
Thanks Again,
Myung
 
> Date: Mon, 20 Apr 2015 02:51:33 +0300
> From: [email protected]
> To: [email protected]
> Subject: Re: [Haskell-beginners] What's the mean of >>=
> 
> Hello!
> 
> >>= and >> are methods of Monad typeclass. Their meaning may be very 
> >>different depending on the actual type. For IO >>= composes a new IO action 
> >>which is, when executed, executes left action first and then passes its 
> >>result to the right function.
> 
> So you can read
> putStr' xs >>= \ x -> putChar '\n'
> as "Execute action putStr' xs, then pass its result to \x -> putChar '\n'".
> 
> Many times the result of previous action is not used (as in above
> example), so there is >> which is like >>= but ignores the result of
> first action.
> It's something like
> x >> y = x >>= (\_ -> y)
> 
> So putStr' xs >> putChar '\n' is the same as putStr' xs >>= \ x -> putChar 
> '\n'
> 
> This code can be rewritten in the do-notation as:
> do
>     putStr' xs
>     putChar '\n'
> 
> To summarize, for IO, >>= and >> are used to sequence actions.
> 
> Best regards,
> Alexey Shmalko
> 
> On Mon, Apr 20, 2015 at 2:33 AM, ??? <[email protected]> wrote:
> > It could be stupid question because i'm very beginner of haskell.
> >
> > I found strange literals when i read haskell code.
> > Does anybody explan what the mean of >>= below ocode ? And additionally,
> > What is mean of >> itself?
> >
> > putStrLn' [] = putChar '\n'
> > putStrLn' xs - putStr' xs >>= \ x -> putChar '\n'
> >
> > putStr' [] = return ()
> > putStr' (x : xs) = putChar x >> putStr' n
> >
> > (because of i18n problem, back slash literal could be shown as '\')
> >
> > Thank you in advance
> > Myung Shin Kim
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150419/8bcf9eb7/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 82, Issue 25
*****************************************

Reply via email to