Bool.agda 1.3 KB

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