如何处理 Agda 不确定是否在 `with` 语句中生成构造函数 case?

How to deal with Agda not being sure in whether to generate constructor case in the `with` statement?

我有以下代码:

open import Data.Nat
open import Agda.Builtin.Char
open import Data.Maybe

digit' : ℕ → Maybe ℕ
digit' n with compare n (primCharToNat '9')
... | greater _ _ = nothing
... | _ = ?

digit : Char → Maybe ℕ
digit c = digit' (primCharToNat c)

不幸的是,emacs 中的 Agda "load file" 命令失败并显示以下消息:

tmp.agda:7,1-8,12
I'm not sure if there should be a case for the constructor less,
because I get stuck when trying to solve the following unification
problems (inferred index ≟ expected index):
  m ≟ n
  suc (m + k) ≟ 57
when checking the definition of with-6

据我所知,Agda 知道 primCharToNat '9' 是一个常数,并且不确定 n 是否总是小于 primCharToNat '9' (57) 是否有任何先决条件。因此,不确定它是否应该生成 less 案例(我假设 equal 案例也是如此)。我能以某种方式强制 Agda 生成所有案例吗?

背景:我正在尝试编写一个 digit : Char → Maybe ℕ 函数,它应该 return 如果传递的字符是十进制数字则 just x 或者如果不是则 nothing .我想到了以下算法:将参数转换为自然数(可能是 ASCII 码) primCharToNat 然后将其与 primCharToNat '0'primCharToNat '9'.

进行比较

一个可能的解决方案是抽象 primCharToNat '9':

digit' : ℕ → Maybe ℕ
digit' n with primCharToNat '9' | compare n (primCharToNat '9')
... | _ | greater _ _ = nothing
... | _ | _ = {!!}