收到 type 的值后Key a
,我可以轻松定义和使用此函数:
keyToInt64 :: Key a -> Int64
keyToInt64 (Key (PersistInt64 n)) = n
keyToInt64 _ = error "wrong database type"
但是,我不能在实例中使用相同的功能Key a
!
instance Num (Key a) where
fromInteger = fromIntegral . keyToInt64
我收到此错误:
Illegal type synonym family application in instance: Key a
In the instance declaration for `Num (Key a)'
我如何定义这个实例?为什么我的方法不起作用?