import Prelude hiding (last, take, unzip) -- The last element of a list with as-pattern: last :: [a] -> a last [x] = x last (x : xs@(_:_)) = last xs -- Splits a list of pairs into their elements: unzip :: [(a,b)] -> ([a],[b]) unzip [] = ([],[]) unzip ((x,y):xys) = (x : xs, y : ys) where (xs,ys) = unzip xys -- Sum up all integers and concatenate all lists: sumConc :: [Either Int String] -> (Int,String) sumConc [] = (0,"") sumConc (x:xs) = case sumConc xs of (sum,cs) -> case x of Left n -> (n+sum, cs) Right s -> (sum, s++cs) fac :: Int -> Int fac n | n == 0 = 1 | otherwise = n * fac (n - 1) -- Returns the prefix with n elements of a list: take :: Int -> [a] -> [a] take n xs | n <= 0 = [] | otherwise = case xs of [] -> [] y:ys -> y : take (n - 1) ys