- Types that are the same but different
- Via concrete types (kind
- Via type constructors (kind
* -> *)
- Constructor must be in scope
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.