1234567891011121314151617181920212223242526272829303132333435363738 |
- map :: (a -> b) -> [a] -> [b]
- map f [] = []
- map f (x:xs) = f x : map f xs
- ----------
- zipWith :: (a->b->c) -> [a]->[b]->[c]
- zipWith z (a:as) (b:bs)
- = z a b : zipWith z as bs
- zipWith _ _ _ = []
- ----------
- zip :: [a] -> [b] -> [(a,b)]
- zip = zipWith (,)
- ----------
- unzip :: [(a,b)] -> ([a],[b])
- unzip = foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])
- ----------
- foldl :: (a -> b -> a) -> a -> [b] -> a
- foldl f z [] = z
- foldl f z (x:xs) = foldl f (f z x) xs
- ----------
- foldr :: (a -> b -> b) -> b -> [a] -> b
- foldr f z [] = z
- foldr f z (x:xs) = f x (foldr f z xs)
- ----------
- take :: Int -> [a] -> [a]
- take n _ | n <= 0 = []
- take _ [] = []
- take n (x:xs) = x : take (n-1) xs
- ----------
- splitAt :: Int -> [a] -> ([a],[a])
- splitAt n xs = (take n xs, drop n xs)
- ----------
|