A function that checks if all vowels in a string are uppercase
Check::String->Bool
Check = undefined
I can only use list comprehension and I can only use Base Functions and Library. Can someone please help me? I know to make it reusable only, for example:
charfound::Char->String->Bool
charFound c(x:xs) | c==x=True
|otherwise=charFoundc XS
You can use notElem
and all
, for example:
check :: String -> Bool
check = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u'])
Here's an explanation:
-
(\e -> e notElem ['a', 'e', 'i', 'o', 'u'])
is a function that takese
and returns whether it is not a lowercase vowel element. -
all
takes a. a predicate that converts elements to boolean and b. an array of these elements and returns whether the predicate is true for all elements in the array.
Another thing that might help is to note that this is written using dot notation , but this is equivalent to
check s = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u']) s