Check::String->Bool
Check = undefined
I can use only list comprehension and I can use only Base Functions and Library functions. I know how to do it recursively only, like this:
charfound::Char->String->Bool
charFound c(x:xs) | c==x=True
|otherwise=charFoundc XS
You can use notElem
, and all
, like this:
check :: String -> Bool
check = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u'])
Here is an explanation:
(\\e -> e notElem ['a', 'e', 'i', 'o', 'u'])
is a function that takes e
, and returns whether it is not an element of the lowercase vowels.
all
takes a. a predicate that transforms elements to booleans, and b. an array of these elements, and returns whether the predicate is true for all elements of the array.
Another thing that might help is to note that this is written using point-free notation , but it is equivalent to
check s = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u']) s
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.