Higher order function map Definition:
map :: (a -> b) -> [a] -> [b]
map f [] = []
map f (x:xs) = f x:map f xs
Then how to write a revmap function with pattern matching/ using function composition?
Higher order function map Definition:
map :: (a -> b) -> [a] -> [b]
map f [] = []
map f (x:xs) = f x:map f xs
Then how to write a revmap function with pattern matching/ using function composition?
Assuming you want something like OCaml's rev_map
function:
revmap :: (a -> b) -> [a] -> [b]
revmap f xs = go xs []
where
go [] acc = acc
go (x:xs) acc = go xs (f x : acc)