所有操作,需要你传一个叫什么 continuation 的东西来接受它的结果
main cont = getLine $ \name ->
putStrLn ("Hello, " ++ name) $ \() ->
getLine $ \age ->
putStrLn ("Hello, " ++ age ++ "-year-old " ++ name) $
cont
所有操作,需要你把它 let 到一个变量
main =
let name = getLine
in let () = putStrLn ("Hello, " ++ name)
in let age = getLine
in putStrLn ("Hello, " ++ age ++ "-year-old " ++ name)
所有操作,需要你把它 bind 出来
main = getLine >>= $ \name ->
putStrLn ("Hello, " ++ name) >>= $ \() ->
getLine >>= $ \age ->
putStrLn ("Hello, " ++ age ++ "-year-old " ++ name)
do
所有操作,需要你把它 <-
到一个变量
main = do
name <- getLine
() <- putStrLn ("Hello, " ++ name)
age <- getLine
putStrLn ("Hello, " ++ age ++ "-year-old " ++ name)
这有啥区别啊
>>=
和 CPS 等价do
-notation 和 ANF 等价