DerivingVia: check via type with empty class list, allow omitting empty class list
If deriving via doesn't list classes then any via type is allowed, this is a bit weird since I usually split deriving via a type into two parts: a) Make sure the via type is coercible, b) choose instances
-- Succeeds
newtype INT = I Int deriving () via Bool
So to help with a) we could change the meaning of deriving () via ViaType
and also allow a new form, deriving via ViaType
. Both of which don't derive any instances but check that the representation of ViaType
matches the datatype being defined.
So I propose both of these parse and compile
newtype INT = I Int deriving via Int
newtype INT = I Int deriving () via Int
and that these two don't:
newtype INT = I Int deriving via Bool
newtype INT = I Int deriving () via Bool
During a livestream someone wrote the via type in a comment
-- Const String
newtype Symbolic f = S String
and I thought to myself.. even if you don't intend to derive instances users should still be able to provide a via type as machine-checked documentation.
newtype Symbolic f = S String
deriving
via Const @(Type->Type) String
:: Type -> Type
witnesses Coercible Symbolic (Const @(Type->Type) String)
.