Forcing2.agda 872 B

123456789101112131415161718192021222324252627282930313233
  1. module Forcing2 where
  2. open import Common.Nat renaming (zero to Z; suc to S)
  3. open import Common.IO
  4. open import Common.Unit
  5. data _**_ (A B : Set) : Set where
  6. _,_ : A -> B -> A ** B
  7. data P {A B : Set} : A ** B -> Set where
  8. _,_ : (x : A)(y : B) -> P (x , y)
  9. data Q {A : Set} : A ** A -> Set where
  10. [_] : (x : A) -> Q (x , x)
  11. test1 : (p : Nat ** Nat) -> P p -> Nat
  12. test1 .(x , y) (x , y) = x + y
  13. test2 : (q : Nat ** Nat) -> Q q -> Nat
  14. test2 .(x , x) [ x ] = ((S (S Z)) * x) + 1
  15. test3 : (q : (Nat ** Nat) ** (Nat ** Nat)) -> Q q -> Nat
  16. test3 .((Z , Z) , (Z , Z)) [ Z , Z ] = Z
  17. test3 .((S n , m) , (S n , m)) [ S n , m ] = S n + m
  18. test3 .((Z , m) , (Z , m)) [ Z , m ] = m
  19. main : IO Unit
  20. main =
  21. printNat (test1 (5 , 8) (5 , 8)) ,,
  22. printNat (test2 (1 , 1) [ 1 ]) ,,
  23. printNat (test3 ( (3 , 4) , (3 , 4) ) [ 3 , 4 ]) ,,
  24. return unit