Prelude.agda 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ------------------------------------------------------------------------
  2. -- Small prelude
  3. ------------------------------------------------------------------------
  4. module Prelude where
  5. infixl 6 _+_
  6. infixr 5 _∷_ _++_
  7. infixr 3 _∨_
  8. infix 2 ¬_
  9. ------------------------------------------------------------------------
  10. -- Some "logic"
  11. data ⊥ : Set where
  12. ¬_ : Set -> Set
  13. ¬ a = a -> ⊥
  14. ------------------------------------------------------------------------
  15. -- Maybe and Dec
  16. data Maybe (a : Set) : Set where
  17. just : a -> Maybe a
  18. nothing : Maybe a
  19. data Dec (a : Set) : Set where
  20. yes : a -> Dec a
  21. no : ¬ a -> Dec a
  22. ------------------------------------------------------------------------
  23. -- Lists
  24. data [_] (a : Set) : Set where
  25. [] : [ a ]
  26. _∷_ : a -> [ a ] -> [ a ]
  27. _++_ : forall {a} -> [ a ] -> [ a ] -> [ a ]
  28. [] ++ ys = ys
  29. (x ∷ xs) ++ ys = x ∷ (xs ++ ys)
  30. ------------------------------------------------------------------------
  31. -- Natural numbers
  32. data ℕ : Set where
  33. zero : ℕ
  34. suc : ℕ -> ℕ
  35. _+_ : ℕ -> ℕ -> ℕ
  36. zero + n = n
  37. suc m + n = suc (m + n)
  38. {-# BUILTIN NATURAL ℕ #-}
  39. {-# BUILTIN NATPLUS _+_ #-}
  40. ------------------------------------------------------------------------
  41. -- Booleans
  42. data Bool : Set where
  43. true : Bool
  44. false : Bool
  45. _∨_ : Bool -> Bool -> Bool
  46. true ∨ _ = true
  47. false ∨ b = b