[Haskell-beginners] Foldable for (,)
Francesco Ariis
fa-ml at ariis.it
Sun Apr 23 08:45:34 UTC 2017
On Sun, Apr 23, 2017 at 08:21:34AM +0000, Jonathon Delgado wrote:
> I've seen many threads, including the one going on now, about why we need
> to have:
>
> length (2,3) = 1
> product (2,3) = 3
> sum (2,3) = 3
> or (True,False) = False
>
> but the justifications all go over my head. Is there a beginner-friendly
> explanation for why such seemingly unintuitive operations should be
> allowed by default?
Hello Jonathon,
the proponents of `Foldable (a,)` see `(2,3)` not as a pair of 'equal'
values, but as a value *and* an annotation, much like some other folks
see Either as having a value (Right a) *or* an annotation (usually an
error in the form of Left e).
So to go back to your examples:
(2,3)
^ ^
| +------------- I am the value
|
+--------------- I am an annotation (and since tuples arguments can
be heterogeneous, I could be a String, a Bool,
anything).
If you agree with this paradigm, `length`, `sum` and friend become a
bit less icky.
I would prefer tuples to be unbiased, but this intuition helped me
connect with the people on the other side of the line.
Does this help?
More information about the Beginners
mailing list