What does the following do expression translate into? (I.e., using >>= operator and lambda functions.) code: -------- h = do a <- (return 1 :: IO Integer) b <- (return 2) return (a + b + 1) -------- -- frigidcode.com indicium.us
Go line by line, except the last one: a) When you see the pattern "a <- b", just swap it with "b >>= \s ->"; b) When you see the pattern "b", put a ">>" at the end of the line. In your case: | h = (return 1 :: IO Integer) >>= \a -> | return 2 >>= \b -> | return (a + b + 1) An example when you have a line without an assignment ("<-"), this: | h = do a <- (return 1 :: IO Integer) | b <- (return 2) | putStrLn "Hello, world!" | return (a + b + 1) Turns into: | h = (return 1 :: IO Integer) >>= \a -> | return 2 >>= \b -> | putStrLn "Hello, world!" >> | return (a + b + 1) 2012/9/4 Christopher Howard <christopher.howard@frigidcode.com>:
What does the following do expression translate into? (I.e., using >>= operator and lambda functions.)
code: -------- h = do a <- (return 1 :: IO Integer) b <- (return 2) return (a + b + 1) --------
participants (3)
-
Christopher Howard -
Ozgur Akgun -
Thiago Negri