[Haskell-beginners] homogeneous value list

allan a.d.clark at ed.ac.uk
Fri Mar 12 08:53:39 EST 2010

This is not bad, I think Daniel's version is a bit more elegant.
One point though, whenever you see "then True else False" you can just 
remove the conditional.
if cexp then True else False is the same as just 'cexp'
Your last line becomes simply:

isHomogeneous (x:xs) = x == head xs && isHomogeneous xs

> 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

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the Beginners mailing list