Specifications of 'any', 'all', 'findIndices'
Tue, 23 Jan 2001 08:28:41 +0100 (MET)
I think a specification
> any p = or . map p
is much more concise than the implementation
> any p  = False
> any p (x:xs) = p x || any p xs
another reason to prefer the higher-level variant
is that the compiler can apply fusion laws, as in
any p . map f = or . map p . map f = or . map (p . f)
(one could also do this starting from the second definition,
but then the compiler's first step would be to derive the
higher-level version from it, I guess)
so it's not at all clear that the above implementation
is indeed more efficient.
I'd rather write clear code, than worry about efficiency too early.
Who said this, "premature optimization is the root of all evil".
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- firstname.lastname@example.org -- phone/fax (+49) 341 9732 204/252 --