Re: [Haskell-beginners] Foldable for (,)

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?

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.

A tuple doesn't only have one value. forall a. ((,) a) only has one value. Fortunately, Haskell has a kind system so we can easily determine what length does.
:k Foldable Foldable :: (* -> *) -> Constraint
Clearly then, if we see a program (length x) where x is a tuple, then we can easily determine that this a constant value 1. For the same reason if we see (length [[1,2,3], [4,5,6]]) and ask, is the length 2 or 6? It's clearly 2; just look at the kind of Foldable. I like types, and types of types. Join me. On 23/04/17 20:06, Jonathon Delgado wrote:
If a tuple only has one value,

On 04/23/2017 08:29 PM, Tony Morris wrote:
A tuple doesn't only have one value. forall a. ((,) a) only has one value. Fortunately, Haskell has a kind system so we can easily determine what length does.
This all makes sense when you realize that Foldable is just the "Object" class from Visual Basic. There's only one sensible way to define a ToString() method on an arbitrary object; therefore it makes sense to provide that method by default, and to have it do the one thing it can do (print garbage).
participants (4)
-
Francesco Ariis
-
Jonathon Delgado
-
Michael Orlitzky
-
Tony Morris