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

Jochem Berndsen jochem at functor.nl
Sun Jun 14 12:29:23 EDT 2009

Toby Miller wrote:
> Here's what I came up with.  I especially like the 2nd version, even
> though it's longer, as it seems very declarative.
> caps1 s = all (\x -> isUpper (head x)) (words s)
> caps2 s = all startsWithUpper (words s) where
>     startsWithUpper w = isUpper (head w)
> I'm also fairly new to Haskell, so I would appreciate feedback from the
> more experienced.

This seems fine, but you need to check that words never returns a list
containing the empty string (otherwise `head' will fail).

I prefer in this case a point free style though, but some might disagree.

Jochem Berndsen | jochem at functor.nl

More information about the Haskell-Cafe mailing list