[Haskell-cafe] New to Haskell - List Comprehension Question

Ross Mellgren rmm-haskell at z.odi.ac
Wed Oct 7 16:50:13 EDT 2009


I don't think a list comprehension is the easiest way to do it, how  
about

upperCase :: String -> String
upperCase [] = []
upperCase (x:xs) = toUpper x : map toLower xs

-Ross

On Oct 7, 2009, at 4:48 PM, Steven1990 wrote:

>
> Hi, I'm currently learning Haskell, and I've been trying to work out a
> function for the following problem for a couple of days now.
>
> I want to use a list comprehension method to change the first letter  
> of a
> string to upper case, and the rest of the string to lower case.
>
> Eg: "heLLo" -> "Hello"
>
> As I'm trying to learn this, I would appreciate hints rather than the
> explicit solution if possible? I'm sure I'm close to a solution, I  
> must be
> missing something though. Driving me crazy!
>
> My attempts are something similar to this:
>
> upperCase :: String -> String
> upperCase xs = [toUpper(x):toLower(xs) | x <- xs]
>
> I think 'toLower' expects a single character rather than the list  
> which is
> one place I'm going wrong?
>
> Thanks in advance,
> Steven
> -- 
> View this message in context: http://www.nabble.com/New-to-Haskell---List-Comprehension-Question-tp25794144p25794144.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com 
> .
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list