我还按照 When (if ever) can type synonyms be partially applied? 中的建议尝试了使用 LiberalTypeSynonyms 扩展进行以下操作。 ,并在 Id
定义中为 f
添加了显式类型签名。我仍然遇到同样的错误。我不知道是否还有其他扩展可能有帮助。
ghci> type Id a = a
ghci> type Const a b = a
ghci> data D f = D (f ())
ghci> (((() :: Id ()) :: ()) :: Const () a)
()
ghci> D () :: D Id
<interactive>:10:9:
Type synonym ‘Id’ should have 1 argument, but has been given none
In an expression type signature: D Id
In the expression: D () :: D Id
In an equation for ‘it’: it = D () :: D Id
这真的让我很困惑。 D
中的 f
为 * -> *
,Id
为 * -> *
。这还有什么?
最佳答案
Haskell 的类型系统不支持部分应用(也称为不饱和)类型同义词或族。不过,data
类型和 newtypes
确实支持部分应用程序。
newtype D f = D (f ())
newtype Id a = Id a
d :: D Id
d = D (Id ())
newtype
在编译期间会被删除,因此您所付出的唯一成本是语法成本。
关于haskell - 为什么类型 Id a = a 不能部分应用于数据 D f = D (f ())?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37997982/