diff --git a/source/Games/List.lagda b/source/Games/List.lagda new file mode 100644 index 000000000..3ab241616 --- /dev/null +++ b/source/Games/List.lagda @@ -0,0 +1,42 @@ +Martin Escardo, Paulo Oliva, 2024 + +The list monad. + +\begin{code} + +{-# OPTIONS --safe --without-K #-} + +module Games.List where + +open import Games.Monad +open import MLTT.Spartan hiding (J) +open import MLTT.List hiding (map) + +𝕃 : Monad +𝕃 = record { + functor = List ; + Ξ· = [_] ; + ext = List-ext ; + ext-Ξ· = concat-singletons ; + unit = List-ext-unit ; + assoc = List-ext-assoc + } + +module List-definitions where + + _βŠ—α΄ΈβΊ_ : {X : Type} {Y : X β†’ Type} + β†’ List X + β†’ ((x : X) β†’ List (Y x)) + β†’ List (Ξ£ x κž‰ X , Y x) + _βŠ—α΄ΈβΊ_ = _βŠ—_ 𝕃 + + ηᴸ⁺ : {X : Type} β†’ X β†’ List X + ηᴸ⁺ = Ξ· 𝕃 + + extᴸ⁺ : {X Y : Type} β†’ (X β†’ List Y) β†’ List X β†’ List Y + extᴸ⁺ = ext 𝕃 + + mapᴸ⁺ : {X Y : Type} β†’ (X β†’ Y) β†’ List X β†’ List Y + mapᴸ⁺ = map 𝕃 + +\end{code} diff --git a/source/Games/index.lagda b/source/Games/index.lagda index bfa949a4a..3139eba7f 100644 --- a/source/Games/index.lagda +++ b/source/Games/index.lagda @@ -17,8 +17,9 @@ import Games.J -- Selection monad. import Games.K -- Continuation (or quantifier) monad. import Games.JK -- Relationship between the two mondas. import Games.Monad -- (Automatically strong, wild) monads on types. -import Games.Reader -import Games.NonEmptyList +import Games.Reader -- Reader monad. +import Games.List -- List monad. +import Games.NonEmptyList -- Non-empty list monad. import Games.TicTacToe0 import Games.TicTacToe1 -- Like TicTacToe0 but using Games.Constructor. import Games.TicTacToe2 -- More efficient and less elegant version. diff --git a/source/MLTT/List.lagda b/source/MLTT/List.lagda index 16242401f..3cfc3a0fe 100644 --- a/source/MLTT/List.lagda +++ b/source/MLTT/List.lagda @@ -409,6 +409,11 @@ List-ext : {X : 𝓀 Μ‡ } {Y : π“₯ Μ‡ } β†’ (X β†’ List Y) β†’ (List X β†’ List Y) List-ext f xs = concat (map f xs) +List-ext-unit : {X : 𝓀 Μ‡ } {Y : π“₯ Μ‡ } + (f : X β†’ List Y) (x : X) + β†’ f x ++ [] = f x +List-ext-unit f x = ([]-right-neutral (f x))⁻¹ + List-ext-assoc : {X : 𝓀 Μ‡ } {Y : π“₯ Μ‡ } {Z : 𝓦 Μ‡ } (g : Y β†’ List Z) (f : X β†’ List Y)