我知道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(boolean) 逻辑的编码:
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/