
On 18 August 2010 10:05, Oleg Lobachev
Hello all,
the and function, and :: [Bool] -> Bool is defined in two different ways in the latest Prelude.
I would expect it to be
and = foldr (&&) True
However, there is a further recursive definition, and it is the one used!
This is just an issue of specification vs implementation. The spec from the H98 report is and = foldr (&&) True An H98 implementation must provide an implementation of 'and' that is equal to this specification. So the above can be used as the implementation, or a directly recursive implementation or versions using build/fold or unfold/destroy fusion, or any other implementation would also be ok so long as they are equal to the spec. As Ivan says, GHC's implementation of 'and' uses build/fold fusion. Note that 'equal' includes all partial and total lists, so you can rely on the above spec to reason about the behaviour on infinite lists and expect that reasoning to work for correct H98 implementations. That said, there are a couple functions where the obviously sensible, and standard implementations differ from the H98 spec for some partial values. Notably splitAt is specified badly in the H98 report (it is too lazy). Duncan