[Haskell-cafe] Generalized null / zero

Niklas Haas haskell at nand.wakku.to
Wed Jan 29 11:20:43 UTC 2014


On Tue, 28 Jan 2014 21:25:31 -0500, "Alvaro J. Genial" <genial at alva.ro> wrote:
> 1. Is there a more general version of `null`? (e.g. for a Monad, Functor,
> Applicative, Traversable or the like.) The closest I can come up with is,
> in decreasing clunkiness:

Lens can do this via the “hasn't” function for any Fold. You can get
some free generalization out of it via “hasn't each”, which works for
every instance of Each (includes most Foldable containers along with
ByteString, Text, and similar).

> 2. In that vein, is there an existing function for "a value or a
> default if
> it's zero"? E.g.:

This abstraction looks a lot like what you'd want out of Alternative,
though admittedly that one is specialized to (* -> *).


More information about the Haskell-Cafe mailing list