
What is <- ? Couldn't find anything on Hoogle. 1) main = do x <- getLine -- get the value from the IO monad putStrLn $ "You typed: " ++ x 2) pythags = do z <- [1..] --get the value from the List monad? x <- [1..z] y <- [x..z] guard (x^2 + y^2 == z^2) return (x, y, z) From: http://en.wikibooks.org/wiki/Haskell/Syntactic_sugar Do and proc notation Sweet Unsweet Monadic binding do x <- getLIne getLine >>= \x -> putStrLn $ "You typed: " ++ x putStrLn $ "You typed: " ++ x So, Example 2 desugared becomes... [1..] >== \z -> ? Michael

getLine >>= \x -> -- x is a string at this point
[1..] >>= \x -> -- x is WHAT at this point?
MIchael
--- On Sun, 8/8/10, Henning Thielemann
So, Example 2 desugared becomes...
[1..] >== \z -> ?
Yes, [1..] >>= \z -> ...

Hi Michael,
although I never used it myself, lists seem strange in the way that when
combining list monads, then all the values go through the chain one by one
-- x will be 1 first, then 2, then 3 and so on.. Try it out, to see. (I
think the result is then also a list of all combinations of results.)
On Sun, Aug 8, 2010 at 5:26 PM, Christopher Done
On 8 August 2010 16:21, michael rice
wrote: getLine >>= \x -> -- x is a string at this point
[1..] >>= \x -> -- x is WHAT at this point?
Num n => n
A number from the list.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

In shortyes, "do z <- ..; foo" desugars to "... >>= \z -> foo"
The Haskell Report describes `do' notation in detail:
http://www.haskell.org/onlinereport/exps.html#sect3.14
Real World Haskell describes its uses:
http://book.realworldhaskell.org/read/io.html#io.bind
On 8 August 2010 15:36, michael rice
What is <- ? Couldn't find anything on Hoogle.
1) main = do x <- getLine -- get the value from the IO monad putStrLn $ "You typed: " ++ x
2) pythags = do z <- [1..] --get the value from the List monad? x <- [1..z] y <- [x..z] guard (x^2 + y^2 == z^2) return (x, y, z)
From: http://en.wikibooks.org/wiki/Haskell/Syntactic_sugar
Do and proc notation
Sweet Unsweet Monadic binding do x <- getLIne getLine >>= \x -> putStrLn $ "You typed: " ++ x putStrLn $ "You typed: " ++ x
So, Example 2 desugared becomes...
[1..] >== \z -> ?
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 8 Aug 2010, at 17:36, michael rice wrote:
What is <- ? Couldn't find anything on Hoogle.
1) main = do x <- getLine -- get the value from the IO monad putStrLn $ "You typed: " ++ x
2) pythags = do z <- [1..] --get the value from the List monad? x <- [1..z] y <- [x..z] guard (x^2 + y^2 == z^2) return (x, y, z)
From: http://en.wikibooks.org/wiki/Haskell/Syntactic_sugar
Do and proc notation
Sweet Unsweet Monadic binding do x <- getLIne getLine >>= \x -> putStrLn $ "You typed: " ++ x putStrLn $ "You typed: " ++ x
So, Example 2 desugared becomes...
[1..] >== \z -> ?
[1..] >>= \z -> [1..z] >>= \x -> [x..z] >>= \y -> guard (x^2 + y^2 == z^2) >> return (x, y, z) Isn't that kinda obvious?
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello michael, Sunday, August 8, 2010, 5:36:05 PM, you wrote: i highly recommend you to read http://sigfpe.blogspot.com/2006/08/you-could-have-invented-monads-and.html that is the best introduction into monads i know and then http://haskell.org/all_about_monads/html/index.html - comprehensive tutorial about many useful monads both are mentioned at http://en.wikipedia.org/wiki/Monad_%28functional_programming%29
What is <- ? Couldn't find anything on Hoogle.
1) main = do x <- getLine -- get the value from the IO monad putStrLn $ "You typed: " ++ x
2) pythags = do z <- [1..] --get the value from the List monad? x <- [1..z] y <- [x..z] guard (x^2 + y^2 == z^2) return (x, y, z)
Do and proc notation
Sweet Unsweet Monadic binding do x <- getLIne getLine >>= \x -> putStrLn $ "You typed: " ++ x putStrLn $ "You typed: " ++ x
So, Example 2 desugared becomes...
[1..] >== \z -> ?
Michael
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (7)
-
Bulat Ziganshin
-
Christopher Done
-
Daniel van den Eijkel
-
Henning Thielemann
-
Markus Läll
-
michael rice
-
Miguel Mitrofanov