Forcing3.agda 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. module Forcing3 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. test : let t : Set
  12. t = (Nat × Nat) × Nat
  13. in (q : t × t) → Q q → Nat
  14. test ._ [ (Z , Z ) , Z ] = Z
  15. test ._ [ (Z , S l) , m ] = S l + m
  16. test ._ [ (S Z , Z ) , m ] = S m
  17. test ._ [ (S Z , S l) , m ] = S Z + m + l
  18. test ._ [ (S (S n) , l ) , m ] = S (S n) + m + l
  19. test ._ [ (n , l ) , m ] = m
  20. main : IO Unit
  21. main = let tTyp : Set
  22. tTyp = (Nat × Nat) × Nat
  23. t0 : tTyp
  24. t0 = (0 , 0) , 0
  25. t1 : tTyp
  26. t1 = (0 , 1) , 2
  27. t2 : tTyp
  28. t2 = (1 , 0) , 3
  29. t3 : tTyp
  30. t3 = (1 , 4) , 5
  31. t4 : tTyp
  32. t4 = (3 , 2) , 10
  33. t5 : tTyp
  34. t5 = (0 , 0) , 4
  35. pn : tTyp → IO Unit
  36. pn t = printNat (test (t , t) [ t ])
  37. in pn t0 ,, -- 0
  38. pn t1 ,, -- 3
  39. pn t2 ,, -- 4
  40. pn t3 ,, -- 9
  41. pn t4 ,, -- 15
  42. pn t5 ,, -- 4
  43. return unit