为什么涉及 "mod" 的相等不在 Idris 中进行类型检查?

Why doesn't equality involving "mod" not typecheck in Idris?

为什么不能进行以下类型检查:

v1 : mod 3 2 = 1
v1 = Refl

然而这将进行类型检查:

v2 : 3 - 2 = 1
v2 = Refl

它的发生是由于 mod 函数的偏向性(感谢 @AntonTrunov 的澄清)。它是多态的,默认情况下数字常量是 Integers.

Idris> :t mod
mod : Integral ty => ty -> ty -> ty
Idris> :t 3
3 : Integer
Idris> :t mod 3 2
mod 3 2 : Integer

对于Integer类型mod功能不全

而是使用 modNatNZ 函数,这样所有类型都可以完美检查并正常工作。

v1 : modNatNZ 3 2 SIsNotZ = 1
v1 = Refl