
length is part of the Foldable class: length = foldl' https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... (\c https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... _ -> c https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... + https://hackage.haskell.org/package/base-4.14.0.0/docs/src/GHC.Num.html#%2B 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 https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... f https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... z https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... (_, y https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm...) = f https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... y https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... z https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Foldable.htm... 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
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.