[Haskell-beginners] homogeneous value list

Roger Whittaker roger at disruptive.org.uk
Fri Mar 12 08:44:21 EST 2010

On Fri, Mar 12, 2010 at 01:27:21PM +0000, Luca Ciciriello wrote:

> I've a list and I want to write a function
> isHomogeneous :: [String] -> Bool
> returning True is all the elements of the list are equals and
> False otherwise. In my first ugly test I've used a
> list-comprehension method, but I'm sure that exists a more
> elegant/short way to obtain the same result.

I'm a total beginner, so I don't know if this is the best way, but
I tried:

isHomogeneous :: [String] -> Bool

isHomogeneous [] = True
isHomogeneous [x] = True
isHomogeneous (x:xs) = if x == head xs && isHomogeneous xs 
                       then True
                       else False

Roger Whittaker
roger at disruptive.org.uk

More information about the Beginners mailing list