I am still a haskell beginner. Can I do a double map in haskell?
For example, if I have a [[Char]] and I want to convert each Char in each [Char] to lower case, is there an easy way to do this rather than something like:
exampleF [] = []
exampleF (x:xs) = (map toLower x) : exampleF xs
In fact, there is a nice pattern here:
map :: (a -> b) -> [a] -> [b]
(map.map) :: (a -> b) -> [[a]] -> [[b]]
(map.map.map) :: (a -> b) -> [[[a]]] -> [[[b]]]
and so on
You can think of map f, as transforming a function f :: a -> b into a function on lists map f :: [a] -> [b], so if you want to transform it further into a function on lists of lists, you just need to use map again to get map (map f) :: [[a]] -> [[b]].
In this particular case, that becomes:
exampleF = map (map toLower)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With