My problem is, I would like to change every lowercase letter of the list ["hello","wHatS", "up?"]
into capitals.
map toUpper [x]
does not work realy...
it should return ["HELLO", "WHATS", "UP?"]..
My problem is, I would like to change every lowercase letter of the list ["hello","wHatS", "up?"]
into capitals.
map toUpper [x]
does not work realy...
it should return ["HELLO", "WHATS", "UP?"]..
Take a look at type of toUpper
, it's Char -> Char
, but you have [[Char]]
. It means that you have two layers of list functor here, so you should map it twice.
For pedagogical reasons we may use map
here, like this:
map (map toUpper) yourList
Parenthesis are important here, we give one argument to map :: (a -> b) -> [a] -> [b]
and get another function of type [Char] -> [Char]
(just what we need!) because of curring.
Once you learn about functors, you may prefer fmap
and <$>
for this task:
(toUpper <$>) <$> yourList