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

Jochem Berndsen jochem at functor.nl
Sun Jun 14 11:44:27 EDT 2009


Gjuro Chensen wrote:
> 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
> 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
> compare it with elem or ASCII values to determine if its upper case.

The idea of using `words' is very good.
If we want to use a bottom-up approach, we should have a function that
determines if a word starts with an upper-case letter, i.e. a function
of type
startsWithUppercase :: String -> Bool
startsWithUppercase  = ...

(Hint: look at 'isUpper' from Data.Char)

Now we need a way to see if for each word, some predicate is satisfied.
There is a standard function for this, "all".
You can also do this by using "map" and "and".

The resulting function can be very concise if you get the hang of it :)

Regards,
-- 
Jochem Berndsen | jochem at functor.nl
GPG: 0xE6FABFAB


More information about the Haskell-Cafe mailing list