length is part of the Foldable class:

length = foldl' (\c _ -> c+1) 0
It is probably defined this way s.t. it satisfies:
length = length . toList
Not the actual definition, but you can read toList as:
toList = foldr (:) []

So as soon as one defines foldr for pairs:
foldr f z (_, y) = f y z
We get:
toList (a,b) = [b]

Using the 'natural' property: length = length . toList
We obtain: length (a,b) = length [b] = 1


On Mon, Nov 23, 2020 at 10:22 AM Manuel Schneckenreither <manuel.schnecki@gmail.com> wrote:
    >>>>> "HT" == Henning Thielemann <lemming@henning-thielemann.de> writes:

    HT> "length (a,b) == 1" is only a consequence of defining instance
    HT> Foldable for pairs. It was not the argument to implement that
    HT> instance, at all.

What was the argument to use 1, not 2 for instance?
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.