List.agda 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. module List where
  2. import Bool
  3. open Bool
  4. infixr 15 _::_
  5. data List (A : Set) : Set where
  6. [] : List A
  7. _::_ : A -> List A -> List A
  8. module Eq {A : Set}(_=A=_ : A -> A -> Bool) where
  9. infix 10 _==_
  10. _==_ : List A -> List A -> Bool
  11. [] == [] = true
  12. x :: xs == y :: ys = (x =A= y) && xs == ys
  13. [] == _ :: _ = false
  14. _ :: _ == [] = false
  15. module Subst {A : Set}(_=A=_ : A -> A -> Bool)
  16. (substA : {x y : A} -> (P : A -> Set) -> IsTrue (x =A= y) -> P x -> P y)
  17. where
  18. module EqA = Eq _=A=_
  19. open EqA
  20. subst : {xs ys : List A} -> (P : List A -> Set) -> IsTrue (xs == ys) -> P xs -> P ys
  21. subst {[] } {_ :: _ } _ () _
  22. subst {_ :: _ } {[] } _ () _
  23. subst {[] } {[] } P eq pxs = pxs
  24. subst {x :: xs} {y :: ys} P eq pxs =
  25. substA (\z -> P (z :: ys)) x==y (
  26. subst (\zs -> P (x :: zs)) xs==ys pxs
  27. )
  28. where
  29. x==y : IsTrue (x =A= y)
  30. x==y = isTrue&&₁ {x =A= y}{xs == ys} eq
  31. xs==ys : IsTrue (xs == ys)
  32. xs==ys = isTrue&&₂ {x =A= y}{xs == ys} eq