haskell - 为什么类型 Id a = a 不能部分应用于数据 D f = D (f ())?

标签 haskell ghc

我还按照 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/

相关文章:

haskell - Xmonad:如何重置主 Pane 中的窗口数量?

Haskell 编译 IO-Action 顺序和刷新

haskell - Haskell Servant从处理程序获取当前路由/URL

windows - Windows 10 上的 GHC -fhpc 代码覆盖率

multithreading - 限制 GHC 中每个线程的线程内存访问

haskell - 函数不仅有类型 : They ARE Types. 和种类。和排序。帮助重振精神

haskell - 导致内存消耗爆炸的标准,看不到 CAF

Haskell 点运算符 : what difference does it make exactly?

ubuntu - 在 Ubuntu 14.04.5 中使用 cabal 时,如何在 Haskell 中安装分析库?

haskell - GHC 链接问题