如何让 Idris 警告不完整 cases/matches?
How to make Idris warn of incomplete cases/matches?
例如,为以下类型实现 Show
实例时:
data Shape = Circle Double
| Box Vector2D
| Polygon (List Vector2D)
| Chain (List Vector2D)
...并省略 Chain
情况,Idris 将成功地对该文件进行类型检查。
实现其他功能也存在类似问题。
在文件开头添加 %default total
似乎无济于事,但我的印象是应该如此。
有一个选项可以调用 idris
:
--total Require functions to be total by default
我仍然不确定这是否是唯一的方法,为什么 %default total
似乎什么都不做,以及是否有可能仅在函数不完整时才收到警告。
有了这个:
%default total
data DataType = A | B | C
Show DataType where
show A = "A"
我明白了
$ idris Testme.idr
Type checking ./Testme.idr
Testme.idr:5:1-13:
|
5 | Show DataType where
| ~~~~~~~~~~~~~
Main.DataType implementation of Prelude.Show.Show is possibly not total due to: Prelude.Show.Main.DataType implementation of Prelude.Show.Show, method show
请注意,您不会在 Atom 中看到此类警告 - 它们似乎不是编译器/编辑器协议的一部分。
例如,为以下类型实现 Show
实例时:
data Shape = Circle Double
| Box Vector2D
| Polygon (List Vector2D)
| Chain (List Vector2D)
...并省略 Chain
情况,Idris 将成功地对该文件进行类型检查。
实现其他功能也存在类似问题。
在文件开头添加 %default total
似乎无济于事,但我的印象是应该如此。
有一个选项可以调用 idris
:
--total Require functions to be total by default
我仍然不确定这是否是唯一的方法,为什么 %default total
似乎什么都不做,以及是否有可能仅在函数不完整时才收到警告。
有了这个:
%default total
data DataType = A | B | C
Show DataType where
show A = "A"
我明白了
$ idris Testme.idr
Type checking ./Testme.idr
Testme.idr:5:1-13:
|
5 | Show DataType where
| ~~~~~~~~~~~~~
Main.DataType implementation of Prelude.Show.Show is possibly not total due to: Prelude.Show.Main.DataType implementation of Prelude.Show.Show, method show
请注意,您不会在 Atom 中看到此类警告 - 它们似乎不是编译器/编辑器协议的一部分。