with 626 B

12345678910111213141516171819202122232425
  1. data Compare : Nat -> Nat -> Set where
  2. same : {x : Nat} -> Compare x x
  3. less : {x : Nat}(y : Nat) -> Compare x (x + suc y)
  4. more : {x : Nat}(y : Nat) -> Compare (x + suc y) x
  5. _-_ : Nat -> Nat -> Nat
  6. x - y | compare x y
  7. x - .x | same = zero
  8. x - .(x + suc y) | less y = zero
  9. .(x + suc y) - x | more y = suc y
  10. -- What does it mean?
  11. _-_ : Nat -> Nat -> Nat
  12. x - y = aux x y (compare x y)
  13. where
  14. aux : (n m : Nat) -> Compare n m -> Nat
  15. aux x .x same = zero
  16. aux x .(x + suc y) (less y) = zero
  17. aux .(x + suc y) x (more y) = suc y
  18. -- Combining pattern matching and with: