
Hi, As some articles say, do notation is expand to (>>) and (>>=) when being compiled. So I want to know the details. Like: main = do a <- getArgs b <- getLine myFunc1 (head a) b myFunc2 b (head a) I cannot figure out what is the (>>) and (>>=) way of this. Thanks.

On 2008 Oct 14, at 23:55, Magicloud wrote:
As some articles say, do notation is expand to (>>) and (>>=) when being compiled. So I want to know the details. Like: main = do a <- getArgs b <- getLine myFunc1 (head a) b myFunc2 b (head a)
I cannot figure out what is the (>>) and (>>=) way of this.
If you are on FreeNode IRC, you can ask lambdabot to @undo such expressions (would need to use braces and semicolons instead of layout though). main = getArgs >>= \a -> getLine >>= \b -> myFunc1 (head a) b >> myFunc2 b (head a) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Magicloud wrote:
Hi, As some articles say, do notation is expand to (>>) and (>>=) when being compiled. So I want to know the details. Like: main = do a <- getArgs b <- getLine myFunc1 (head a) b myFunc2 b (head a)
I cannot figure out what is the (>>) and (>>=) way of this.
Thanks. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
getArgs >>= (\a -> getLine >>= (\b -> myFunc1 (head a) b >> myFunc2 b (head a))) - -- Tony Morris http://tmorris.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFI9WqJmnpgrYe6r60RAhAEAKCNvJaxziyZ3g9wGUOoJpcx4/MrtwCfVnlL ZflntZ5xrDOCv3kHgcuMP18= =21PH -----END PGP SIGNATURE-----

On Wed, 2008-10-15 at 11:55 +0800, Magicloud wrote:
Hi, As some articles say, do notation is expand to (>>) and (>>=) when being compiled. So I want to know the details.
If you want to know the details, ask the Report. It's perfectly readable. http://www.haskell.org/onlinereport/

Magicloud wrote:
Hi, As some articles say, do notation is expand to (>>) and (>>=) when being compiled. So I want to know the details. Like: main = do a <- getArgs b <- getLine myFunc1 (head a) b myFunc2 b (head a)
I cannot figure out what is the (>>) and (>>=) way of this.
Thanks.
In the beginning, their was the bind (>>=) operator and lambdas. You bind the results of one action to the argument of the next (act >>= \a -> act2 a) A genious realized that not all actions have an intersting result, so instead of a meaningless binding (act >>= \_ -> act2) you can sequence the actions (act >> act2). So code would look like: ------------------ main = getArgs >>= \a -> getLine >>= \b -> myFunc1 (head a) b >> myFunc2 b (head a) ------------------ It didn't take too long and people got in the habbit of lining up the binding on the right-most column: ------------------ main = getArgs >>= \a -> getLine >>= \b -> myFunc1 (head a) b >> myFunc2 b (head a) ------------------ And eventually someone figured out this looked an aweful lot like imparitive code with the variable and function flipped around (and some ugly characters inbetween). getArgs >>= \a -> ~ a = getArgs(); So the shortest most non-descript word, 'do', was found to ensure no one would have to type much. Tom * Story not historically accurate. Technical accuracy is questionable. Sanity of author not guarenteed. All rights reserved. No refunds.
participants (6)
-
Brandon S. Allbery KF8NH
-
Derek Elkins
-
Jason Dusek
-
Magicloud
-
Thomas M. DuBuisson
-
Tony Morris