← Back to More on functions
- Lambdas are a nice way to avoid defining unnecessary separate functions. Convert the following let- or where-bindings to lambdas:
map f xs where f x = x * 2 + 3
let f x y = read x + y in foldr f 1 xs
- Sections are just syntactic sugar for lambda operations. I.e.
(+2) is equivalent to
\x -> x + 2. What would the following sections 'desugar' to? What would be their types?
map (\x -> x * 2 + 3) xs
foldr (\x y -> read x + y) 1 xs
(\x -> 4 + x) :: Int -> Int
(\xs -> elem 1 xs) :: [Int] -> Bool
(\c -> notElem c "abc") :: Char -> Bool