[Haskell-cafe] Textbook example of instance Foldable ((,) a)

Sven Panne svenpanne at gmail.com
Mon Nov 23 20:18:03 UTC 2020


Am Mo., 23. Nov. 2020 um 16:32 Uhr schrieb Sebastiaan Joosten <
sjcjoosten+haskell at gmail.com>:

> [...] We obtain: length (a,b) = length [b] = 1
>

Quoting my former self (
https://mail.haskell.org/pipermail/libraries/2017-April/027905.html), you
get even more "fun" stuff with lots of potential for late-night debugging
hours:

   maximum (3,2)   =>   2
   minimum (4,5)   => 5
   sum (6,7)   =>   7
   product (8,9)   =>   9

Yes, you can think of (X, Y) as "Y with context X" or "a one-element
container with Y in it", but is this really what comes to your mind
first? I still highly doubt that. The Foldable-Traversable-in-Prelude
change was largely a good thing, but very surprising (and not really
needed) changes coming stealthily with it were only communicated when
it was already too late... :-/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20201123/37ebc9ce/attachment.html>


More information about the Haskell-Cafe mailing list