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

Gregory Crosswhite gcross at phys.washington.edu
Wed Oct 7 16:52:35 EDT 2009


Hint:  Move the boundary case outside the comprehension, and then use  
the comprehension to handle the normal case.

Also, FYI, a comprehension feeds each value of the list xs into x, and  
then evaluates the expression to the left of the pipe with that single  
value of x.

Cheers,
Greg


On Oct 7, 2009, at 1: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