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

Daniel Fischer daniel.is.fischer at web.de
Sun Jun 14 11:59:42 EDT 2009

Am Sonntag 14 Juni 2009 17:19:22 schrieb Gjuro Chensen:
> Hello everyone!
> Im a Haskell newbie, and Ive have few unanswered questions. For someone
> more experienced (at least I think so) its a very simple task, but I just
> cant get a grip on it and its pretty frustrating. It wouldn't be that bad
> if I haven't browse thru bunch of pages and tutorials and still nothing...
> The problem is: take a string, and if every words starts with uppercase
> letter then print yes, else no.
> Forum Text Bold -> yes
> Frog image File -> no
> Ive had my share of approaches to this, but I just cant make it work.
> Standard one seemed the most simple:
> search :: String -> String
> search [] = []
> and then use words (splits string on space) to split the string so I could

That's good.
So you have

everyWordStartsWithAnUppercaseLetter string = doSomething (words string)

doSomething :: [String] -> Bool


wordStartsWithAnUppercaseLetter :: String -> Bool

for each word in the list and returns True if all words satisfy the condition, False if 

There's a handy function in the prelude for that:

Prelude> :t all
all :: (a -> Bool) -> [a] -> Bool

> get a list and go through it recursively. But how to apply words to entered
> string in this form?
> To find the first letter I came up with: first = take 1 (head x). And

No, I don't think that's what you want:

Prelude> :t (take 1 . head)
(take 1 . head) :: [[a]] -> [a]

Since String is a synonym for [Char], "head" gets the first letter of a word.

> compare it with elem or ASCII values to determine if its upper case.

What about unicode strings?

Prelude> :t Data.Char.isUpper
Data.Char.isUpper :: Char -> Bool

is what you want.

> Any help, advice or suggestion is appreciated.
> Thanks in advance!

How to assemble that is left to you.

More information about the Haskell-Cafe mailing list