Deriving via

Contents

The DerivingVia GHC extension provides the via deriving strategy, which lets your type copy typeclass instances from other types.

The type providing the instances and the type receiving the instances have to be representationally equivalentAnother way to say this is that the two types have to be coercible with each other. – more or less the same, distinguished only by one or more layers of newtype definitions. This may sound fairly limited, but it turns out that a suprising variety of situations satisfy this condition. Haskellers write newtypes a lot, especially when introducing interesting typeclass instances.

Types that are the same but different

Sign up for access to the full page, plus the complete archive and all the latest content.