import Prelude hiding (last, unzip, take) -- Last element of a list. last :: [a] -> a last (x : xs@(_:_)) = last xs last [x] = x -- [x] == x : [] unzip :: [(a,b)] -> ([a], [b]) unzip [] = ([], []) unzip ((x,y) : xys) = case unzip xys of (xs, ys) -> (x:xs, y:ys) -- Adds all integer and concatenates all string in a mixed list: sumConc :: [Either Int String] -> (Int,String) sumConc [] = (0, "") sumConc (x:xs) = case sumConc xs of (n,s) -> case x of Left m -> (m+n, s) Right t -> (n, t ++ s) fac :: Integer -> Integer fac n | n == 0 = 1 | otherwise = n * fac (n - 1) -- Take the first n elements of a list: take :: Int -> [a] -> [a] take n xs | n <= 0 = [] | otherwise = case xs of [] -> [] (x:xs) -> x : take (n - 1) xs