全函数中的等式证明和模式匹配
Equality proofs and pattern matching in total functions
我知道这是一个有点人为的例子,但我想知道如何使以下函数完整:
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 = 10
目前类型检查器抱怨:
Main.foo is not total as there are missing cases
编辑:
将 impossible
分支添加到 HTNWs 答案 我通过这种方式对其进行了类型检查:
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 {prf = Refl} = 10
foo x {prf = Refl} impossible
你也必须在等式上进行模式匹配
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 {prf=Refl} = 10
我知道这是一个有点人为的例子,但我想知道如何使以下函数完整:
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 = 10
目前类型检查器抱怨:
Main.foo is not total as there are missing cases
编辑:
将 impossible
分支添加到 HTNWs 答案 我通过这种方式对其进行了类型检查:
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 {prf = Refl} = 10
foo x {prf = Refl} impossible
你也必须在等式上进行模式匹配
total foo : (x : Int) -> {auto prf : x = 10} -> Int
foo 10 {prf=Refl} = 10