[Hugs-users] converting to capital letters

Alex Teslin alexteslin at yahoo.co.uk
Thu Oct 19 17:13:58 EDT 2006


Hi, 
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 have managed to do with two functions:

capitalise :: String -> String
capitalise xs = [capitalise2 ch| ch<-xs]

capitalise2 :: Char -> Char
capitalise2 ch 
    | isLower ch    = chr (ord ch - 32)
    | otherwise    = ch

But in the book exercise it asks to define as a single function. I tried like this:

capitalise :: String -> String
capitalise xs = [chr (ord ch - 32) | ch<-xs, isLower ch]

But this returns only converted characters, the rest is ignored.

Any help would be much appriciated.

 Send instant messages to your online friends http://uk.messenger.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/hugs-users/attachments/20061019/ded75679/attachment.htm


More information about the Hugs-Users mailing list