\begin{code} {-# OPTIONS --cubical --safe #-} open import Algebra open import Level module Control.Monad.Weighted.Functor {ā} {š : Type ā} (rng : Semiring š ) where open Semiring rng open import Level open import Control.Monad.Weighted.Definition rng open import Function open import Path open import Prelude open import Control.Monad.Weighted.Functor.TypeDef private variable p q : Level P : Weighted A ā Type p Q : Weighted A ā Type q private module DisplayFunctors where module SimpleFunctor where \end{code} %<*simple-functor-def> \begin{code} data š (A : Type a) (B : Type b) : Type (a āā b āā ā) where [] : š A B _ā_ā·_ : š ā A ā B ā š A B \end{code} %</simple-functor-def> %<*functor-def> \begin{code} data š (A : Type a) (P : Weighted A ā Type p) : Type (a āā p āā ā) where [] : š A P _ā_ā·_āØ_ā© : š ā A ā (xs : Weighted A) ā P xs ā š A P \end{code} %</functor-def> \begin{code} š : (A : Type a) ā (Weighted A ā Type p) ā Type (a āā p āā ā) š A = š-F š (Weighted A) A \end{code} %<*map> \begin{code} map : (P ā Q) ā š A P ā š A Q map f [] = [] map f (w ā x ā· xs āØ ĻāØxsā© ā©) = w ā x ā· xs āØ f ĻāØxsā© ā© \end{code} %</map> %<*wrap> \begin{code} āŖ_ā« : š A P ā Weighted A āŖ [] ā« = [] āŖ w ā x ā· xs āØ _ ā© ā« = w ā x ā· xs \end{code} %</wrap> %<*wrap-map> \begin{code} map-id : (f : P ā Q) (xs : š A P) ā āŖ xs ā« ā” āŖ map f xs ā« map-id f [] = refl map-id f (_ ā _ ā· _ āØ _ ā©) = refl \end{code} %</wrap-map> %<*alg> \begin{code} Alg : (A : Type a) (P : Weighted A ā Type p) ā Type _ Alg A P = (xs : š A P) ā P āŖ xs ā« \end{code} %</alg>