I'm having trouble understanding how this recursion works, for example, if I want to make a String -> Boolean
exercise to know if the string has a lower case in it how can i do it?This is my big amateur code, thats not even running the list properly, although I don't know any better:
lowercase (x:xs) | isLower x lowercase xs = True
| otherwise = False
You have a good idea, but bad syntax.
lowercase :: String -> Bool
lowercase [] = True -- this case is needed to ensure that recursion stops
lowercase (x:xs) | isLower x = lowercase xs
lowercase _ = False
Or, using standard library,
lowercase = all isLower
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments