遞歸
使用遞歸求List中得最大值,先設置邊界條件,如果List為空,則運行異常,如果List只有一個元素,直接返回,如果List中第一個元素大于尾部的最大值則它是最大的,否則尾部最大值最大
maximum' [] = error "error" maximum' [x] = x maximum' (x:xs) = | x > maxTail = x | otherwise = maxTail' where maxTail = maximum' xs
take' n _
| n <= 0 = []
take' _ [] = []
take' n (x:xs) = x : take' (n - 1) xs
zip' _ [] = []
zip' [] _ =[]
zip' (x:xs) (y:ys) = (x, y) : zip' xs ys
</pre></code>
####函數
#####Curried functions
本質上Haskell上的函數值有一個參數的,但以前有多個參數的函數是什么回事。例如max函數,其實它也是一個參數,只是先把1作為參數,然后返回另一個函數,繼續把2當做參數
max 1 2
(max 1) 2