
I really appeciate your answer. Thanks Again, Myung
Date: Mon, 20 Apr 2015 02:51:33 +0300 From: rasen.dubi@gmail.com To: beginners@haskell.org 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, 김명신
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 Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners