-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCore.agda
54 lines (39 loc) · 1.36 KB
/
Core.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{-# OPTIONS --cubical-compatible #-}
module Class.Applicative.Core where
open import Class.Prelude
open import Class.Core
open import Class.Functor.Core
record Applicative {a b} (F : Type a → Type b) : Type (lsuc (a ⊔ b)) where
infixl 4 _<*>_ _⊛_ _<*_ _<⊛_ _*>_ _⊛>_
infix 4 _⊗_
field
overlap ⦃ super ⦄ : Functor F
pure : A → F A
_<*>_ : F (A → B) → F A → F B
_⊛_ = _<*>_
_<*_ : F A → F B → F A
x <* y = const <$> x ⊛ y
_*>_ : F A → F B → F B
x *> y = constᵣ <$> x ⊛ y
_<⊛_ = _<*_; _⊛>_ = _*>_
_⊗_ : F A → F B → F (A × B)
x ⊗ y = (_,_) <$> x ⊛ y
zipWithA : (A → B → C) → F A → F B → F C
zipWithA f x y = f <$> x ⊛ y
zipA : F A → F B → F (A × B)
zipA = zipWithA _,_
open Applicative ⦃...⦄ public
record Applicative₀ {a b} (F : Type a → Type b) : Type (lsuc (a ⊔ b)) where
field
overlap ⦃ super ⦄ : Applicative F
ε₀ : F A
open Applicative₀ ⦃...⦄ public
record Alternative {a b} (F : Type a → Type b) : Type (lsuc (a ⊔ b)) where
infixr 3 _<|>_
field _<|>_ : F A → F A → F A
open Alternative ⦃...⦄ public
infix -1 ⋃⁺_ ⋃_
⋃⁺_ : ⦃ Alternative F ⦄ → List⁺ (F A) → F A
⋃⁺_ = foldr₁ _<|>_
⋃_ : ⦃ Applicative₀ F ⦄ → ⦃ Alternative F ⦄ → List (F A) → F A
⋃_ = foldr _<|>_ ε₀