[Haskell-cafe] Textbook example of instance Foldable ((,)a)
Viktor Dukhovni
ietf-dane at dukhovni.org
Wed Nov 25 17:52:56 UTC 2020
> On Nov 25, 2020, at 3:26 PM, Zemyla <zemyla at gmail.com> wrote:
>
> Except we would, because we need to be able to express instances like first in Arrow using builtin pairs, rather than try and write some sort of combination for every pair and arrow. And I'm pretty sure there are other libraries which depend on pairs too.
This is why I posted the not terribly ergonomic:
newtype T2 a b = T2 { _unT2 :: (a, b) }
which has a free coercion to a pair, so you can pass a pair
to any library that needs one, without any runtime overhead.
This of course takes much discipline to use when refactoring
data types, in order to avoid missing needed changes obscured
by unwanted instances of the built-in pair.
Wherever you need a pair, you'd have to write "(coerce t2)",
rather than "t2".
--
Viktor.
More information about the Haskell-Cafe
mailing list