[Haskell-beginners] Foldable for (,)

Francesco Ariis fa-ml at ariis.it
Sun Apr 23 10:56:38 UTC 2017


On Sun, Apr 23, 2017 at 10:06:00AM +0000, Jonathon Delgado wrote:
> If a tuple only has one value, why do functions for operating over sets
> make sense at all? I can see from your explanations why the answers could
> be considered correct (if a particular convention is assumed), but why
> does the operation make sense at all? It seems like we're asking for the
> length of a single value, its product, etc.

I can only guess: consistency. Once you create an instance of `Foldable`
you instantly get some functions "for free". Among those are foldMap,
foldr etc. *and* sum, length and friends.

I cannot see an occurrence where writing `length (x, y)` instead of 1
makes sense.


More information about the Beginners mailing list