Unique.agda 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module Unique where
  2. open import Category
  3. module Uniq (ℂ : Cat) where
  4. private open module C = Cat ℂ
  5. -- We say that f ∈! P iff f is the unique arrow satisfying P.
  6. data _∈!_ {A B : Obj}(f : A ─→ B)(P : A ─→ B -> Set) : Set where
  7. unique : (forall g -> P g -> f == g) -> f ∈! P
  8. itsUnique : {A B : Obj}{f : A ─→ B}{P : A ─→ B -> Set} ->
  9. f ∈! P -> (g : A ─→ B) -> P g -> f == g
  10. itsUnique (unique h) = h
  11. data ∃! {A B : Obj}(P : A ─→ B -> Set) : Set where
  12. witness : (f : A ─→ B) -> f ∈! P -> ∃! P
  13. getWitness : {A B : Obj}{P : A ─→ B -> Set} -> ∃! P -> A ─→ B
  14. getWitness (witness w _) = w
  15. uniqueWitness : {A B : Obj}{P : A ─→ B -> Set}(u : ∃! P) ->
  16. getWitness u ∈! P
  17. uniqueWitness (witness _ u) = u
  18. witnessEqual : {A B : Obj}{P : A ─→ B -> Set} -> ∃! P ->
  19. {f g : A ─→ B} -> P f -> P g -> f == g
  20. witnessEqual u {f} {g} pf pg = trans (sym hf) hg
  21. where
  22. h = getWitness u
  23. hf : h == f
  24. hf = itsUnique (uniqueWitness u) f pf
  25. hg : h == g
  26. hg = itsUnique (uniqueWitness u) g pg