我知道TypeSynomymInstances only allows fully applied type synonyms to be used in instance heads ,但如果我也可以使用部分应用的类型同义词似乎会很方便。
例如:
class Example e where
thingy :: a -> b -> e a b
-- legit, but awkward
newtype FuncWrapper e a b = FuncWrapper { ap :: a -> e a b }
instance (Example e) => Example (FuncWrapper e) where
thingy _ = FuncWrapper . flip thingy
funcWrapperUse :: (Example e) => e Int String
funcWrapperUse = thingy 1 "two" `ap` 3 `ap` 4 `ap` 5
-- not legal, but a little easier to use
type FuncSynonym e a b = a -> e a b
instance (Example e) => Example (FuncSynonym e) where
thingy _ = flip thingy
funcSynonymUse :: (Example e) => e Int String
funcSynonymUse = thingy 1 "two" 3 4 5
最佳答案
Haskell 中根本不允许使用部分应用的类型同义词。部分应用的同义词实际上是一个函数,其输入是未应用的类型,其输出是一个类型。例如,这里是 bool 逻辑的编码:
type True x y = x
type False x y = y
type Not b x y = b y x
type And b1 b2 x y = b1 (b2 x y) y
type Or b1 b2 x y = b1 x (b2 x y)
要确定两个部分应用的类型同义词是否相等,类型检查器必须确定函数是否相等。这是一个很难解决的问题,一般来说它是不可判定的。
关于haskell - 为什么 TypeSynonymInstances 不允许在实例头中使用部分应用的类型同义词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922560/