[Haskell-cafe] Textbook example of instance Foldable ((,)a)
Viktor Dukhovni
ietf-dane at dukhovni.org
Wed Nov 25 20:16:22 UTC 2020
On Wed, Nov 25, 2020 at 07:56:49PM +0000, Barak A. Pearlmutter wrote:
> True. And their use in Arrow is a great example of pairs that do *not*
> work well as instances of Foldable as currently defined. Arrow is
> using pairs as abstract Cartesian products, and the natural
> isomorphism A×B≅B×A is used implicitly all the time. The Foldable
> definition for pairs breaks that symmetry inappropriately.
The "symmetry breaking" is not a result of the perhaps regrettable
Foldable instance, rather it is a basic consequence of the fact that
given:
data Foo a b = Foo a b
we immediately get a Functor "Foo a :: * -> *" for each a, of which
"(,) a" is but one example. I find nothing objectionable in the Functor
instance "(,) a" or the Bifunctor instance "(,)". It is only the
Traversable and Foldable instances of "(,) a" that have the noted
unexpected behaviour.
--
Viktor.
More information about the Haskell-Cafe
mailing list