| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Monads on indexed sets (predicates) |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- Note that currently the monad laws are not included here. |
| 8 |
|
| 9 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 10 |
|
| 11 |
module Effect.Monad.Predicate where |
| 12 |
|
| 13 |
open import Data.Product.Base using (_,_) |
| 14 |
open import Effect.Monad.Indexed using (RawIMonad) |
| 15 |
open import Function.Base using (const; id; _∘_) |
| 16 |
open import Level using (Level; _⊔_; suc) |
| 17 |
open import Relation.Binary.PropositionalEquality.Core using (refl) |
| 18 |
open import Relation.Unary using (_⊆_; _⇒_; _∈_; _∩_; {_}) |
| 19 |
open import Relation.Unary.PredicateTransformer using (Pt) |
| 20 |
|
| 21 |
private |
| 22 |
variable |
| 23 |
i ℓ : Level |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
|
| 27 |
record RawPMonad {I : Set i} (M : Pt I (i ⊔ ℓ)) : Set (suc (i ⊔ ℓ)) where |
| 28 |
|
| 29 |
infixl 1 _?>=_ _?>_ _>?>_ _?>=′_ |
| 30 |
infixr 1 _=<?_ _<?<_ |
| 31 |
|
| 32 |
-- ``Demonic'' operations (the opponent chooses the state). |
| 33 |
|
| 34 |
field |
| 35 |
return? : ∀ {P} → P ⊆ M P |
| 36 |
_=<?_ : ∀ {P Q} → P ⊆ M Q → M P ⊆ M Q |
| 37 |
|
| 38 |
_?>=_ : ∀ {P Q} → M P ⊆ const (P ⊆ M Q) ⇒ M Q |
| 39 |
m ?>= f = f =<? m |
| 40 |
|
| 41 |
_?>=′_ : ∀ {P Q} → M P ⊆ const (∀ j → {_ : P j} → j ∈ M Q) ⇒ M Q |
| 42 |
m ?>=′ f = m ?>= λ {j} p → f j {p} |
| 43 |
|
| 44 |
_?>_ : ∀ {P Q} → M P ⊆ const (∀ {j} → j ∈ M Q) ⇒ M Q |
| 45 |
m₁ ?> m₂ = m₁ ?>= λ _ → m₂ |
| 46 |
|
| 47 |
join? : ∀ {P} → M (M P) ⊆ M P |
| 48 |
join? m = m ?>= id |
| 49 |
|
| 50 |
_>?>_ : {P Q R : _} → P ⊆ M Q → Q ⊆ M R → P ⊆ M R |
| 51 |
f >?> g = _=<?_ g ∘ f |
| 52 |
|
| 53 |
_<?<_ : ∀ {P Q R} → Q ⊆ M R → P ⊆ M Q → P ⊆ M R |
| 54 |
g <?< f = f >?> g |
| 55 |
|
| 56 |
-- ``Angelic'' operations (the player knows the state). |
| 57 |
|
| 58 |
rawIMonad : RawIMonad (λ i j A → i ∈ M (const A ∩ { j })) |
| 59 |
rawIMonad = record |
| 60 |
{ return = λ x → return? (x , refl) |
| 61 |
; _>>=_ = λ m k → m ?>= λ { {._} (x , refl) → k x } |
| 62 |
} |
| 63 |
|
| 64 |
open RawIMonad rawIMonad public |