import SimplePrelude hiding ((.), curry, uncurry, const) ---------------------------------------------------------------------------- -- Combinators: take some functions and yield another function -- Function composition: combine two functions sequentially (.) :: (b -> c) -> (a -> b) -> (a -> c) g . f = \x -> g (f x) -- Add the ASCII values of all uppercase letters in a string: sumUC :: String -> Int sumUC = sum . filter (\c -> c>64 && c<91) . map ord -- Transform a function on pairs into a curryfied function: curry :: ((a,b) -> c) -> a -> b -> c --curry f = \x y -> f (x,y) curry f x y = f (x,y) uncurry :: (a -> b -> c) -> (a,b) -> c uncurry f (x,y) = f x y -- Scalar product: add all products of pairwise elements in two vectors: scalar :: [Int] -> [Int] -> Int scalar xs ys = sum (map (uncurry (*)) (zip xs ys)) -- The constant function where the first argument is the constant value: const :: a -> b -> a const x _ = x