Clowns.agda 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {-# OPTIONS --no-positivity-check #-}
  2. module Clowns where
  3. import Equality
  4. import Isomorphism
  5. import Derivative
  6. import ChainRule
  7. open import Sets
  8. open import Functor
  9. open import Zipper
  10. open import Dissect
  11. open Functor.Recursive
  12. open Functor.Semantics
  13. -- Natural numbers
  14. NatF : U
  15. NatF = K [1] + Id
  16. Nat : Set
  17. Nat = μ NatF
  18. zero : Nat
  19. zero = inn (inl <>)
  20. suc : Nat -> Nat
  21. suc n = inn (inr n)
  22. plus : Nat -> Nat -> Nat
  23. plus n m = fold NatF φ n where
  24. φ : ⟦ NatF ⟧ Nat -> Nat
  25. φ (inl <>) = m
  26. φ (inr z) = suc z
  27. -- Lists
  28. ListF : (A : Set) -> U
  29. ListF A = K [1] + K A × Id
  30. List' : (A : Set) -> Set
  31. List' A = μ (ListF A)
  32. nil : {A : Set} -> List' A
  33. nil = inn (inl <>)
  34. cons : {A : Set} -> A -> List' A -> List' A
  35. cons x xs = inn (inr < x , xs >)
  36. sum : List' Nat -> Nat
  37. sum = fold (ListF Nat) φ where
  38. φ : ⟦ ListF Nat ⟧ Nat -> Nat
  39. φ (inl <>) = zero
  40. φ (inr < n , m >) = plus n m
  41. TreeF : U
  42. TreeF = K [1] + Id × Id
  43. Tree : Set
  44. Tree = μ TreeF
  45. leaf : Tree
  46. leaf = inn (inl <>)
  47. node : Tree -> Tree -> Tree
  48. node l r = inn (inr < l , r >)