Bool.agda 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module Bool where
  2. import Logic
  3. open Logic
  4. data Bool : Set where
  5. false : Bool
  6. true : Bool
  7. infixr 5 _&&_
  8. _&&_ : Bool -> Bool -> Bool
  9. true && x = x
  10. false && _ = false
  11. not : Bool -> Bool
  12. not true = false
  13. not false = true
  14. IsTrue : Bool -> Set
  15. IsTrue true = True
  16. IsTrue false = False
  17. IsFalse : Bool -> Set
  18. IsFalse x = IsTrue (not x)
  19. module BoolEq where
  20. _==_ : Bool -> Bool -> Bool
  21. true == x = x
  22. false == x = not x
  23. subst : {x y : Bool}(P : Bool -> Set) -> IsTrue (x == y) -> P x -> P y
  24. subst {true}{true} _ _ px = px
  25. subst {false}{false} _ _ px = px
  26. subst {true}{false} _ () _
  27. subst {false}{true} _ () _
  28. isTrue== : {x : Bool} -> IsTrue x -> IsTrue (x == true)
  29. isTrue== {true} _ = tt
  30. isTrue== {false} ()
  31. infix 1 if_then_else_
  32. if_then_else_ : {A : Set} -> Bool -> A -> A -> A
  33. if true then x else y = x
  34. if false then x else y = y
  35. open BoolEq
  36. if'_then_else_ : {A : Set} -> (x : Bool) -> (IsTrue x -> A) -> (IsFalse x -> A) -> A
  37. if' true then f else g = f tt
  38. if' false then f else g = g tt
  39. isTrue&&₁ : {x y : Bool} -> IsTrue (x && y) -> IsTrue x
  40. isTrue&&₁ {true} _ = tt
  41. isTrue&&₁ {false} ()
  42. isTrue&&₂ : {x y : Bool} -> IsTrue (x && y) -> IsTrue y
  43. isTrue&&₂ {true} p = p
  44. isTrue&&₂ {false} ()