[Haskell-cafe] Haskell - string to list isusses, and more

Jochem Berndsen jochem at functor.nl
Sun Jun 14 13:18:21 EDT 2009

Gjuro Chensen wrote:
> startsWithUpper :: String -> Bool
> startsWithUpper []= False
> startsWithUpper string =
> 	if myIsUpper(head(string)) then True 
> 	else False

It is very good that you caught the issue of taking the head of an empty
list :)
I saw here and also below, that you did things like
if P then True else False
You can shorten this to 'P'.

Also, normally Haskellers like to pattern match, changing the second
clause of your function into
startsWithUpper (x:xs) = myIsUpper x

> check :: [String] -> Bool
> check []=False

Why is this False and not True? Certainly in the empty string all words
start with an uppercase letter, don't they? (If it's True, you can even
remove this clause, and let the other one take care of the rest.)


Jochem Berndsen | jochem at functor.nl

More information about the Haskell-Cafe mailing list