@@ -16,11 +16,12 @@ module 1Lab.Membership where
1616-- propositions, either. In practice, both of these conditions are
1717-- satisfied.
1818
19- record Membership {ℓ ℓe} (A : Type ℓe) (ℙA : Type ℓ) ℓm : Type (ℓ ⊔ lsuc ( ℓe ⊔ ℓm) ) where
19+ record Membership {ℓ ℓe} (A : Type ℓe) (ℙA : Type ℓ) ℓm : Type (ℓ ⊔ ℓe ⊔ lsuc ℓm ) where
2020 field _∈_ : A → ℙA → Type ℓm
2121 infix 30 _∈_
2222
2323open Membership ⦃ ... ⦄ using (_∈_) public
24+ {-# DISPLAY Membership._∈_ i a b = a ∈ b #-}
2425
2526-- The prototypical instance is given by functions into a universe:
2627
@@ -38,17 +39,37 @@ _∉_ : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {ℙA : Type ℓ'} ⦃ m : Membershi
3839 → A → ℙA → Type ℓ''
3940x ∉ y = ¬ (x ∈ y)
4041
41- -- Inclusion relative to the _∈_ projection.
42-
43- _⊆_ : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {ℙA : Type ℓ'} ⦃ m : Membership A ℙA ℓ'' ⦄
44- → ℙA → ℙA → Type (ℓ ⊔ ℓ'')
45- _⊆_ {A = A} S T = (a : A) → a ∈ S → a ∈ T
42+ infix 30 _∉_
4643
4744-- Total space of a predicate.
48-
4945∫ₚ
5046 : ∀ {ℓ ℓ' ℓ''} {X : Type ℓ} {ℙX : Type ℓ'} ⦃ m : Membership X ℙX ℓ'' ⦄
5147 → ℙX → Type _
5248∫ₚ {X = X} P = Σ[ x ∈ X ] (x ∈ P)
5349
54- infix 30 _∉_ _⊆_
50+ -- Notation typeclass for _⊆_. We could always define
51+ --
52+ -- S ⊆ T = ∀ x → x ∈ S → x ∈ T
53+ --
54+ -- but this doesn't work too well for collections where the element type
55+ -- is more polymorphic than the collection type, e.g. sieves, where we
56+ -- would instead like
57+ --
58+ -- S ⊆ T = ∀ {i} (x : F i) → x ∈ S → x ∈ T
59+ --
60+ -- Instead we can define _⊆_ as its own class, then write a default
61+ -- instance in terms of _∈_.
62+
63+ record Inclusion {ℓ} (ℙA : Type ℓ) ℓi : Type (ℓ ⊔ lsuc (ℓi)) where
64+ field _⊆_ : ℙA → ℙA → Type ℓi
65+ infix 30 _⊆_
66+
67+ open Inclusion ⦃ ... ⦄ using (_⊆_) public
68+ {-# DISPLAY Inclusion._⊆_ i a b = a ⊆ b #-}
69+
70+ instance
71+ Inclusion-default
72+ : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {ℙA : Type ℓ'} ⦃ m : Membership A ℙA ℓ'' ⦄
73+ → Inclusion ℙA (ℓ ⊔ ℓ'')
74+ Inclusion-default {A = A} = record { _⊆_ = λ S T → (a : A) → a ∈ S → a ∈ T }
75+ {-# INCOHERENT Inclusion-default #-}
0 commit comments