Consider this definition:
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
As innocent as it looks, it would not type check.
|
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)
For some reason, it cannot locate the right prf
. (Or is there something else going on?) For some reason again, this error, while appearing in the second summand, can be fixed by annotating the minus in the first. This compiles:
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
My questions:
- What is happening?
- How can I express this logic better?
- Can I supply implicit arguments to infix operators, such as
-
, without converting them to prefix form(-)
?