open import Cat.Diagram.Coproduct.Indexed
open import Cat.Functor.FullSubcategory
open import Cat.Thin.Instances.Sub
open import Cat.Diagram.Coproduct
open import Cat.Instances.Slice
open import Cat.Instances.Sets
open import Cat.Morphism
open import Cat.Prelude
open import Cat.Thin
open import Data.Sum
import Cat.Thin.Limits
module wip.test4 {ℓ} where
private variable X : Set ℓ
open Precategory
open /-Hom
open /-Obj
module _ {X : Set ℓ} where
module P = Poset (Subobjects (Sets ℓ) Sets-is-category X)
open Cat.Thin.Limits {P = Poset.→Proset (Subobjects (Sets ℓ) Sets-is-category X)}
module _ {I : Type ℓ} {F : I → P.Ob} where
cup = Σ[ i ∈ I ] ∣ F i .object .domain ∣
inj : cup → ∣ X ∣
inj (i , x) = F i .object .map x
img = image inj
sub : P.Ob
sub .object .domain = img , Σ-is-hlevel 2 (X .is-tr) λ _ → is-prop→is-set squash
sub .object .map = fst
sub .witness = embedding→monic (Subset-proj-embedding λ _ → squash)
injs : ∀ i → P.Hom (F i) sub
injs i .map x = F i .object .map x , inc ((i , x) , refl)
injs i .commutes = refl
is-coprod : is-indexed-coproduct (Subobj (Sets ℓ) X) {S = sub} F injs
is-coprod = indexed-join→indexed-coproduct injs (λ {B} → proj {B = B}) where
proj : {B : P.Ob} → (∀ i → F i P.≤ B) → sub P.≤ B
proj {B = B} f .map (y , p) = ∥-∥-elim {P = λ _ → fibre (B .object .map) y}
(λ _ → monic-between-sets→is-embedding (X .is-tr)
(λ {C = C} → B .witness {c = C}) y)
(λ { ((i , x) , p) → f i .map x , happly (f i .commutes) _ ∙ p })
p .fst
proj {B = B} f .commutes = funext λ where
(y , p) → ∥-∥-elim
(λ x → X .is-tr (B .object .map (proj {B = B} f .map (y , x))) _)
(λ { ((i , x) , p) → happly (f i .commutes) _ ∙ p })
p
open import Agda.Builtin.Maybe
private variable A : Type
just-injective : ∀ {x y} → Path (Maybe A) (just x) (just y) → x ≡ y
just-injective {x = x} p = J (λ y p → x ≡ unjust x y) refl p
where unjust : A → Maybe A → A
unjust x (just x₁) = x₁
unjust x nothing = x