我正在构建一个模块,每次我编写一个函数时,它都会调用其他一些不存在的函数.显然它们最终会存在,但是在我编写代码之前能够进行语法检查会很好.
是否有一些标志组合,我可以使用GHC发出警告,而不是"名称foo不在范围内"的错误?
(如果GHC可以为不存在的名称选择一个类型签名,并且确认程序仍然可以进行类型检查,那将是很好的.这几乎就是"类型漏洞"功能所做的 - 但是要使用那,你仍然需要手动定义所有的标识符.)
bhe*_*ilr 11
使用命名TypedHoles:
> let f x = _g . _h x $ x
Found hole ‘_g’ with type: b0 -> c
Where: ‘b0’ is an ambiguous type variable
‘c’ is a rigid type variable bound by
the inferred type of f :: s -> c at <interactive>:2:5
Relevant bindings include
x :: s (bound at <interactive>:2:7)
f :: s -> c (bound at <interactive>:2:5)
In the first argument of ‘(.)’, namely ‘_g’
In the expression: _g . _h x
In the expression: _g . _h x $ x
Found hole ‘_h’ with type: s -> s -> b0
Where: ‘b0’ is an ambiguous type variable
‘s’ is a rigid type variable bound by
the inferred type of f :: s -> c at <interactive>:2:5
Relevant bindings include
x :: s (bound at <interactive>:2:7)
f :: s -> c (bound at <interactive>:2:5)
In the expression: _h
In the second argument of ‘(.)’, namely ‘_h x’
In the expression: _g . _h x
Run Code Online (Sandbox Code Playgroud)
所以这给你,_g :: b0 -> c并_h :: s -> s -> b0与上下文x :: s和f :: s -> c.类型检查器可以在大多数时间推断这些类型(这是重点TypedHoles),你可以给它们命名.如果你愿意,你可以定义所有的功能与_作为符号名的第一个字符,然后再使用您的编辑器替换_(.+)\b用\1.如果你想解决_name用于记录领域的镜头惯例,那么只需在你的孔名称上加上2个下划线.
这仍然会使您的代码无法编译,但是如果您将-fdefer-type-errors它们结合使用,它们将被报告为警告,允许您在运行时发生类型错误.