So i have to count every word in a list of strings in Haskell
Example:
Cwords ["one string random", "hello asd", "asd"] -> 6
This is how i tried:
Cwords :: [String] -> Int
Cwords = length . map words
Now it gives 3 for the same input
For each element of the list, you want to find the length of the words, aka map (length . words). You'll then have an [Int] where each element is the length of the words in that element, so you want to sum it up:
cwords :: [String] -> Int
cwords = sum . map (length . words)
Note that functions must start with a lowercase letter.
map f xswill always be a list with the same length asxs, no matter what functionfis.