[Haskell-beginners] homogeneous value list

Daniel Fischer daniel.is.fischer at web.de
Fri Mar 12 08:41:11 EST 2010


Am Freitag 12 März 2010 14:27:21 schrieb Luca Ciciriello:
> Hi.
>
> I know, this is a very basic question but I've had some trouble with it.
>
>
>
> 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.
>
>
>
> Thanks in advance for any answer.

isHomogeneous :: Eq a => [a] -> Bool
isHomogeneous [] = True
isHomogeneous (x:xs) = all (== x) xs

>
>
>
> Luca



More information about the Beginners mailing list