\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>