aboutsummaryrefslogtreecommitdiff
path: root/NaturalTransformation/Instance/ListAppend.agda
blob: 05a31f581f9c7f4a1e219a2febb990b827268f24 (plain)
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
{-# OPTIONS --without-K --safe #-}

open import Level using (Level; _⊔_)

module NaturalTransformation.Instance.ListAppend {c  : Level} where

open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper)
open import Categories.Category.Product using (_※_)
open import Categories.Category.BinaryProducts using (module BinaryProducts)
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-Cartesian)
open import Categories.Category.Cartesian using (Cartesian)
open import Categories.Functor using (Functor; _∘F_)
open import Data.List using (_++_; map)
open import Data.List.Properties using (map-++)
open import Data.List.Relation.Binary.Pointwise using (++⁺)
open import Data.Product.Relation.Binary.Pointwise.NonDependent using (_×ₛ_)
open import Data.Product using (_,_)
open import Functor.Instance.List {c} {} using (List)
open import Function using (Func; _⟶ₛ_)
open import Relation.Binary using (Setoid)

module List = Functor List

open Cartesian (Setoids-Cartesian {c} {c  }) using (products)
open BinaryProducts products using (-×-)
open Func

++ₛ : {X : Setoid c }  List.₀ X ×ₛ List.₀ X ⟶ₛ List.₀ X
++ₛ .to (xs , ys) = xs ++ ys
++ₛ .cong (≈xs , ≈ys) = ++⁺ ≈xs ≈ys

map-++ₛ
  : {A B : Setoid c }
    (f : Func A B)
    (xs ys : Data.List.List (Setoid.Carrier A))
   (open Setoid (List.₀ B))
   map (to f) xs ++ map (to f) ys  map (to f) (xs ++ ys)
map-++ₛ {_} {B} f xs ys = ListB.sym (ListB.reflexive (map-++ (to f) xs ys))
  where
    module ListB = Setoid (List.₀ B)

++ : NaturalTransformation (-×- ∘F (List  List)) List
++ = ntHelper record
    { η = λ X  ++ₛ {X}
    ; commute = λ { {A} {B} f {xs , ys}  map-++ₛ f xs ys }
    }