Tuples
和 Python 的 Tuple 很类似,Haskell 在 Tuple 上定义了一些有用的函数
1 | -- std::pair.first |
tuple 上也可以进行 pattern matching
1 | swap :: (a,b) -> (b,a) |
Folding
什么是 folding? 给定一个列表
1 | -- foldr, 类似于求数组的和 |
Type Classes
1 | (==) :: (Eq a) => a -> a -> Bool |
For all types a that belong to the class Eq, this is a function of type a -> a -> Bool. That is, if the type a is a member of the class Eq, you can give two values of type a to == and get a Bool result.