Tuple.agda 806 B

12345678910111213141516171819202122232425262728293031323334353637
  1. -- examples for termination with tupled arguments
  2. module Tuple where
  3. data Nat : Set where
  4. zero : Nat
  5. succ : Nat -> Nat
  6. data Pair (A : Set) (B : Set) : Set where
  7. pair : A -> B -> Pair A B
  8. -- uncurried addition
  9. add : Pair Nat Nat -> Nat
  10. add (pair x (succ y)) = succ (add (pair x y))
  11. add (pair x zero) = x
  12. data T (A : Set) (B : Set) : Set where
  13. c1 : A -> B -> T A B
  14. c2 : A -> B -> T A B
  15. {-
  16. -- constructor names do not matter
  17. add' : T Nat Nat -> Nat
  18. add' (c1 x (succ y)) = succ (add' (c2 x y))
  19. add' (c2 x (succ y)) = succ (add' (c1 x y))
  20. add' (c1 x zero) = x
  21. add' (c2 x zero) = x
  22. -- additionally: permutation of arguments
  23. add'' : T Nat Nat -> Nat
  24. add'' (c1 x (succ y)) = succ (add'' (c2 y x))
  25. add'' (c2 (succ y) x) = succ (add'' (c1 x y))
  26. add'' (c1 x zero) = x
  27. add'' (c2 zero x) = x
  28. -}