- Description of syntactic sugar
Summary of the various uses of syntactic sugar in Haskell
- For more information, see the chapter 深入函數
description
|
sweet
|
unsweet
|
sections
|
(+2)
(3-)
|
\x -> x + 2
\x -> 3 - x
|
- For more information, see the chapters 列表和元組 and 深入列表
description
|
sweet
|
unsweet
|
lists |
[1,2,3] |
1:2:3:[]
|
arithmetic sequences
|
[1..5]
[1,3..9]
[1..]
[1,3..]
|
enumFromTo 1 5
enumFromThenTo 1 3 9
enumFrom 1
enumFromThen 1 3
|
list comprehensions |
[ x | (x,y) <- foos, x < 2 ]
|
let ok (x,y) = if x < 2 then [x] else []
in concatMap ok foos
|
- For more information, see the chapters 理解 Monad and Arrows
description
|
sweet
|
unsweet
|
Sequencing
|
do putStrLn "one"
putStrLn "two"
|
putStrLn "one" >>
putStrLn "two"
|
Monadic binding
|
do x <- getLine
putStrLn $ "You typed: " ++ x
|
getLine >>= \x ->
putStrLn $ "You typed: " ++ x
|
Let binding
|
do let f xs = xs ++ xs
putStrLn $ f "abc"
|
let f xs = xs ++ xs
in putStrLn $ f "abc"
|
- For more information on layout, see the chapter on 縮進
|
The 語法糖 module是這本維基書Haskell中的一個草稿。 你可以通過擴展它來幫助維基書。
|