I am a newbie in Haskell and have some problem of defining a function that would convert all small letters to capital and leave the rest intact.
I tried solving this question in my book so far:
capitalise :: String -> String
capitalise xs = [capitalise2 ch| ch<-xs]
capitalise2 :: Char -> Char
capitalise2 ch
| isLower ch = chr (ord ch - 32)
| otherwise = ch
I am getting errors:
p3.hs:6:7: Not in scope: `isLower'
p3.hs:6:23: Not in scope: `chr'
p3.hs:6:28: Not in scope: `ord'
Any help would be much appreciated.
First, you need to
import Data.Charto use those functions it is complaining about.Right, you are missing the
otherwisecase in the new function. Try it with anif .. then .. elseconstruct. Experienced Haskellers do not use that construct very much; I would probably do it with a helper function:which is pretty much the same as what you already have, the main difference being the scope of the helper function.
See also Data.Char.toUpper.
This may also be a good opportunity to break free of list comprehensions and start to play with higher order functions. Try writing this function with map instead of a list comprehension.