[Haskell-cafe] Textbook example of instance Foldable ((,) a)

Henning Thielemann lemming at henning-thielemann.de
Tue Nov 24 19:40:34 UTC 2020


On Tue, 24 Nov 2020, Viktor Dukhovni wrote:

> And of course, when refactoring, instead of moving to a 2-tuple, that 
> brings in possibly unwanted instances, one can instead choose a custom 
> product type, that does not have a Foldable instance:
>
>    -- coercible to a 2-tuple if/as needed
>    newtype T2 a b = T2 { _unT2 :: (a, b) } deriving (Eq, Ord, Show)
>
> to give one's 2-tuples exactly the desired instances and no more.  This 
> admittedly is not terribly ergonomic.

If people would use custom pair types we would not need Foldable on pairs, 
at all.


More information about the Haskell-Cafe mailing list