指定解释范围以将十进制字符串解释为 Nat

specify interpretation scope to interpret decimal string as Nat

有没有办法告诉 Idris 将 210 等十进制字符串解释为 Nat? repl 中的默认行为是将它们解释为 Integer。例如,在 Coq 中,可以使用 % 指定解释范围来消除符号歧义,所以我想我希望存在 10%Nat 之类的东西。伊德里斯有类似的东西吗?

标准序曲包含

the : (a : Type) -> (value: a) -> a
the _ = id

可用于给出显式类型:

the Integer 10
the Nat 6
the (Vect 3 Int) [1,2,3]

还有with [namespace] [expr],在expr里面有权限namespace。这似乎更接近 %,但 the 似乎更常用。

with Vect [['a', 'b']] -- Vect 1 (Vect 2 Char)
with List [['a', 'b']] -- List (List Char)

您可以为the做一个语法扩展:

syntax [expr] "%" [type] = the type expr
5%Nat
10%Int

但不适用于 with