[Haskell-beginners] Foldable for (,)

Jonathon Delgado voldermort at hotmail.com
Sun Apr 23 10:06:00 UTC 2017


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.

Francesco Ariis 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