On 7/19/07, Alexteslin <[EMAIL PROTECTED]> wrote:
What wrong with my original solution?

allEqual2 :: [Int] -> Bool
allEqual2 xs = length xs == length (filter isEqual xs)
        where
        isEqual n = (head xs) == n

It looks simpler to me

I believe it's correct, but the use of "length" and "filter" seems forced.

For example, for a very long list that has the second element
mismatch, the versions with explicit recursion (or fold variants) will
terminate with False as soon as a mismatch is found; the "length"
version will not terminate until both have been fully traversed.

If you're allowed to use everything, perhaps the clearest would be:

allEqual3 [] = True
allEqual3 (x:xs) = all (== x) xs

(with "all" built on top of a fold.)

Colin
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to