表达式为"A._"的Haskell令牌

Hen*_*ing 1 syntax haskell typed-holes

Haskell如何解释表达式A._?例如main = print $ A._.

Haskell抛出以下错误错误:

source_file.hs:1:16:
    Found hole ‘_’ with type: r0
    Where: ‘r0’ is an ambiguous type variable
    Relevant bindings include
      main :: IO ()
        (bound at source_file.hs:1:1)
    In the second argument of ‘($)’, namely ‘A._’
    In the expression: print $ A._
    In an equation for ‘main’: main = print $ A._
Run Code Online (Sandbox Code Playgroud)

但是,根据Haskell的语法参考,A._应该被解释为consym (A),varsym (.)并且reservedid (_),因为_不是有效的varid(varids不能是reservedids).

Haskell抛出相同的错误main = print $ A._t:

source_file.hs:1:16:
    Found hole ‘_t’ with type: r0
    Where: ‘r0’ is an ambiguous type variable
    Relevant bindings include
      main :: IO ()
        (bound at source_file.hs:1:1)
    In the second argument of ‘($)’, namely ‘A._t’
    In the expression: print $ A._t
    In an equation for ‘main’: main = print $ A._t
Run Code Online (Sandbox Code Playgroud)

然而在这种情况,该令牌序列应该qvarid (A._t)A比赛modid_t比赛varid.

任何人都可以帮我解释发生了什么吗?

Ale*_*lec 5

这些是类型化的孔,它们是默认启用的GHC扩展的一部分.从这个链接:

类型化孔是GHC的一个特征,它允许使用前导下划线(例如" _"," _foo"," _bar")编写的特殊占位符用作表达式.在编译期间,这些孔将生成一条错误消息,描述在孔的位置预期的类型,有关任何自由类型变量的原点的信息,以及可能有助于填充实际代码的漏洞的本地绑定列表.在GHC中始终启用类型孔.

这意味着A._将其解析为组合的应用程序,(.)构造函数A和类型化的孔表达式_.这同样适用A._t.

输入孔的目的主要是调试:它让您知道GHC在该位置应该具有什么类型的表达式,并在错误消息中报告.