【发布时间】:2026-01-03 06:35:01
【问题描述】:
考虑这个定义:
h : Nat -> Nat -> Nat
h x y = case 1 `isLTE` x of
(Yes prf) => case 1 `isLTE` y of
(Yes prf') => (x - 1) * 2 + (y - 1)
(No contra) => ?sr_3
(No contra) => ?h_2
虽然看起来很无辜,但它不会进行类型检查。
|
14 | (Yes prf') => (x - 1) * 2 + (y - 1)
| ^
...
When checking an application of function Prelude.Interfaces.-:
Type mismatch between
Nat (Type of y)
and
LTE 1 x (Expected type)
由于某种原因,它无法找到正确的prf。 (或者还有其他事情发生吗?) 再次出于某种原因,这个错误虽然出现在第二个加法中,但可以通过在第一个加法中注释减号来修复。这样编译:
h : Nat -> Nat -> Nat
h x y = case 1 `isLTE` x of
(Yes prf) => case 1 `isLTE` y of
(Yes prf') => ((-) {smaller = prf} x 1) * 2 + (y - 1)
(No contra) => ?sr_3
我的问题:
- 发生了什么?
- 如何更好地表达这个逻辑?
- 我能否为中缀运算符(例如
-)提供隐式参数,而不将它们转换为前缀形式(-)?
【问题讨论】:
标签: idris