[Haskell-cafe] Data.Foldable.all and empty list
Kim-Ee Yeoh
ky3 at atamo.com
Wed Sep 30 04:04:35 UTC 2015
On Wed, Sep 30, 2015 at 4:33 AM, Lana Black <lanablack at amok.cc> wrote:
> Is there any particular reason why the 'all' function returns True when
> supplied with an empty list (or any other foldable)? I'm aware that it
> is implemented via All monoid instance, my question is whether this
> behaviour is intentional or it can be considered a bug.
>
Hi Lana, this is a good question, variants of which are actually asked
quite often.
The function 'all' has type signature (a -> Bool) -> [a] -> Bool.
Given a list of as that's split arbitrarily into bs and cs such that as ==
bs ++ cs,
'all' has the property that: all p as == all p bs && all p cs, for any
boolean predicate p.
So if bs or cs is the empty list, the property forces all f [] == True.
For a similar Q&A on related functions, see
https://groups.google.com/forum/#!msg/elm-discuss/sPS98RnV0Og/dSddTp8VXYcJ
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150930/cc0c7364/attachment.html>
More information about the Haskell-Cafe
mailing list