| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Applicative functors on indexed sets (predicates) |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- Note that currently the applicative functor laws are not included |
| 8 |
-- here. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
module Effect.Applicative.Predicate where |
| 13 |
|
| 14 |
open import Effect.Functor.Predicate |
| 15 |
open import Data.Product.Base using (_,_) |
| 16 |
open import Function.Base using (const; constᵣ) |
| 17 |
open import Level using (Level; suc; _⊔_) |
| 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 RawPApplicative {I : Set i} (F : Pt I ℓ) : |
| 28 |
Set (i ⊔ suc ℓ) where |
| 29 |
infixl 4 _⊛_ _<⊛_ _⊛>_ |
| 30 |
infix 4 _⊗_ |
| 31 |
|
| 32 |
field |
| 33 |
pure : ∀ {P} → P ⊆ F P |
| 34 |
_⊛_ : ∀ {P Q} → F (P ⇒ Q) ⊆ F P ⇒ F Q |
| 35 |
|
| 36 |
rawPFunctor : RawPFunctor F |
| 37 |
rawPFunctor = record |
| 38 |
{ _<$>_ = λ g x → pure g ⊛ x |
| 39 |
} |
| 40 |
|
| 41 |
private |
| 42 |
open module RF = RawPFunctor rawPFunctor public |
| 43 |
|
| 44 |
_<⊛_ : ∀ {P Q} → F P ⊆ const (∀ {j} → F Q j) ⇒ F P |
| 45 |
x <⊛ y = const <$> x ⊛ y |
| 46 |
|
| 47 |
_⊛>_ : ∀ {P Q} → const (∀ {i} → F P i) ⊆ F Q ⇒ F Q |
| 48 |
x ⊛> y = constᵣ <$> x ⊛ y |
| 49 |
|
| 50 |
_⊗_ : ∀ {P Q} → F P ⊆ F Q ⇒ F (P ∩ Q) |
| 51 |
x ⊗ y = (_,_) <$> x ⊛ y |
| 52 |
|
| 53 |
zipWith : ∀ {P Q R} → (P ⊆ Q ⇒ R) → F P ⊆ F Q ⇒ F R |
| 54 |
zipWith f x y = f <$> x ⊛ y |