Basics.agda 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module Basics where
  2. _%_ : {A B : Set}{C : B -> Set}
  3. (f : (x : B) -> C x)(g : A -> B)(x : A) -> C (g x)
  4. f % g = \x -> f (g x)
  5. -- Logic
  6. data False : Set where
  7. record True : Set where
  8. tt : True
  9. tt = _
  10. ¬_ : Set -> Set
  11. ¬ A = A -> False
  12. record ∃ {A : Set}(P : A -> Set) : Set where
  13. field
  14. witness : A
  15. proof : P witness
  16. ∃-intro : {A : Set}{P : A -> Set}(x : A) -> P x -> ∃ P
  17. ∃-intro x p = record { witness = x; proof = p }
  18. infixr 15 _/\_ _×_
  19. data _×_ (A B : Set) : Set where
  20. _,_ : A -> B -> A × B
  21. _/\_ = _×_
  22. -- Maybe
  23. data Lift (A : Set) : Set where
  24. bot : Lift A
  25. lift : A -> Lift A
  26. _=<<_ : {A B : Set} -> (A -> Lift B) -> Lift A -> Lift B
  27. f =<< bot = bot
  28. f =<< lift v = f v
  29. -- Nat
  30. data Nat : Set where
  31. zero : Nat
  32. suc : Nat -> Nat
  33. -- Identity
  34. infix 10 _==_
  35. data _==_ {A : Set}(x : A) : A -> Set where
  36. refl : x == x
  37. data Id {A : Set}(x : A) : Set where
  38. it : (y : A) -> x == y -> Id x
  39. -- Booleans
  40. data Bool : Set where
  41. true : Bool
  42. false : Bool
  43. data LR : Set where
  44. left : LR
  45. right : LR
  46. if_then_else_ : {A : Set} -> Bool -> A -> A -> A
  47. if true then x else y = x
  48. if false then x else y = y
  49. -- Lists
  50. infixr 50 _::_
  51. data List (A : Set) : Set where
  52. [] : List A
  53. _::_ : A -> List A -> List A
  54. data Elem {A : Set}(x : A) : List A -> Set where
  55. hd : forall {xs} -> Elem x (x :: xs)
  56. tl : forall {y xs} -> Elem x xs -> Elem x (y :: xs)