{-# OPTIONS --without-K --safe #-}
module Categories.Category.Core where
open import Level
open import Function.Base using (flip)
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
import Relation.Binary.Reasoning.Setoid as SetoidR
record Category (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
eta-equality
infix 4 _≈_ _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : Rel Obj ℓ
_≈_ : ∀ {A B} → Rel (A ⇒ B) e
id : ∀ {A} → (A ⇒ A)
_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)
field
assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → (h ∘ g) ∘ f ≈ h ∘ (g ∘ f)
sym-assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → h ∘ (g ∘ f) ≈ (h ∘ g) ∘ f
identityˡ : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f
identityʳ : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f
identity² : ∀ {A} → id ∘ id {A} ≈ id {A}
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
∘-resp-≈ : ∀ {A B C} {f h : B ⇒ C} {g i : A ⇒ B} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
module Equiv {A B : Obj} = IsEquivalence (equiv {A} {B})
open Equiv
∘-resp-≈ˡ : ∀ {A B C} {f h : B ⇒ C} {g : A ⇒ B} → f ≈ h → f ∘ g ≈ h ∘ g
∘-resp-≈ˡ pf = ∘-resp-≈ pf refl
∘-resp-≈ʳ : ∀ {A B C} {f h : A ⇒ B} {g : B ⇒ C} → f ≈ h → g ∘ f ≈ g ∘ h
∘-resp-≈ʳ pf = ∘-resp-≈ refl pf
hom-setoid : ∀ {A B} → Setoid _ _
hom-setoid {A} {B} = record
{ Carrier = A ⇒ B
; _≈_ = _≈_
; isEquivalence = equiv
}
o-level : Level
o-level = o
ℓ-level : Level
ℓ-level = ℓ
e-level : Level
e-level = e
module HomReasoning {A B : Obj} where
open SetoidR (hom-setoid {A} {B}) public
infixr 4 _⟩∘⟨_ refl⟩∘⟨_
infixl 5 _⟩∘⟨refl
_⟩∘⟨_ : ∀ {M} {f h : M ⇒ B} {g i : A ⇒ M} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
_⟩∘⟨_ = ∘-resp-≈
refl⟩∘⟨_ : ∀ {M} {f : M ⇒ B} {g i : A ⇒ M} → g ≈ i → f ∘ g ≈ f ∘ i
refl⟩∘⟨_ = Equiv.refl ⟩∘⟨_
_⟩∘⟨refl : ∀ {M} {f h : M ⇒ B} {g : A ⇒ M} → f ≈ h → f ∘ g ≈ h ∘ g
_⟩∘⟨refl = _⟩∘⟨ Equiv.refl
infix 2 ⟺
infixr 3 _○_
⟺ : {f g : A ⇒ B} → f ≈ g → g ≈ f
⟺ = Equiv.sym
_○_ : {f g h : A ⇒ B} → f ≈ g → g ≈ h → f ≈ h
_○_ = Equiv.trans
op : Category o ℓ e
op = record
{ Obj = Obj
; _⇒_ = flip _⇒_
; _≈_ = _≈_
; _∘_ = flip _∘_
; id = id
; assoc = sym-assoc
; sym-assoc = assoc
; identityˡ = identityʳ
; identityʳ = identityˡ
; identity² = identity²
; equiv = equiv
; ∘-resp-≈ = flip ∘-resp-≈
}