Key entity
is a synonym for KeyBackend backend entity
, so you need to define the instance on the concrete type.
instance Num (KeyBackend backend entity) where
Key (PersistInt64 a) + Key (PersistInt64 b) = Key . PersistInt64 $ a + b
Key _ + _ = error "wrong database type"
_ + Key _ = error "wrong database type"
...
Though using error
so gratuitously is likely to cause a lot of pain later.