BJGJCKMBY65UJSUP4DGEQVR2DZAXWDJKRVOGGTKQDQ4XAMBRLRZAC 4L2YWRMCKZ56NCRC44XVDZQ5BEKHX26C4GQZ5TIL35Y33VKFTBCQC CO3C7GSZ2X62ALXW2EAWDHCRSXCNVKIIHCL47GYZ32OHZER4NLZQC K7TT3LDM6HYYXLSYFSJZRQZ6GOGTDJ7F5KFU7GBPJOKN2DHJLHMQC XNPLRKJ4ZK442XNJ5BC7TO3DKXGXFSOSGBZBPW5HZZDHY3IVD6FAC NYMIFK2WBHU4G34QF4GZP63ATL2EQC6PLAQLWZMUTPDGDPQUEKVQC 4KXMGXQ6PTWVMINMKRCQE7DIJXUYMO7SVNR6AQ243QULY7IZLUYAC RUIGRXTKM6BQ532W7KU3RKDXMRNRGDVGMA2ODMX2D2F3PCLF3GAQC ZJMXCVWEW2XHBZGNQUHTW7JRIAEAE5UDTASSD75WJG55MDOUZ3MAC YE3EAD3XYKXRHEJN4VLBVBQM2EISKFHAESPOZ6S4QMLA6YZEVDQQC 4WZ2PYVOKVZFB6Q44LR6APOSMZTUR566HI5IOFLDCA5C7RQRMFRAC PUFI27GBQLTD64UCR35JZOWINUF2A5BWFUI5G6ZQN3UFQZPZB54AC import Builtinimport Algebra.Relation.Equivalenceimport Algebra.Control.Functorimport Algebra.Control.Applicativeimport Algebra.Control.Monadimport Algebra.Group.Magmaimport Algebra.Group.Semigroupimport Algebra.Group.Monoid%default totalinfixr 7 ::public exportdata LinkedList t = Nil | (::) t (LinkedList t)data LinkedListEquiv : Equivalence t => (a, b : LinkedList t) -> Type whereBothEmpty : (e : Equivalence t) => LinkedListEquiv @{e} Nil NilEquivHeadAndTail : (e : Equivalence t) => {a, b : t} -> {x, y : LinkedList t}-> (ok1: Equiv a b) -> (ok2: LinkedListEquiv x y)-> LinkedListEquiv @{e} (a :: x) (b :: y)public export(e : Equivalence a) => Uninhabited (LinkedListEquiv @{e} Nil (h :: t)) whereuninhabited BothEmpty impossibleuninhabited (EquivHeadAndTail h t) impossiblepublic export(e : Equivalence a) => Uninhabited (LinkedListEquiv @{e} (h :: t) Nil) whereuninhabited BothEmpty impossibleuninhabited (EquivHeadAndTail h t) impossiblepublic exportfromNotEquivHead : (e : Equivalence t) => {a, b : t} -> (ok: Not (Equiv a b))-> Not (LinkedListEquiv @{e} (a :: x) (b :: y))fromNotEquivHead ctr (EquivHeadAndTail prf _) = ctr prf
public exportfromNotEquivTail : (e : Equivalence t) => (ok: Not (LinkedListEquiv @{e} x y))-> Not (LinkedListEquiv @{e} (a :: x) (b :: y))fromNotEquivTail ctr (EquivHeadAndTail _ prf) = ctr prf
import public Data.LinkedList.Basic
decLinkedListEquiv : (e : Equivalence t) => (a, b : LinkedList t) -> Dec (LinkedListEquiv @{e} a b)decLinkedListEquiv Nil Nil = Yes BothEmptydecLinkedListEquiv Nil (_::_) = No absurddecLinkedListEquiv (_::_) Nil = No absurddecLinkedListEquiv @{e} (h1::t1) (h2::t2) =case (decEquiv @{e} h1 h2, decLinkedListEquiv t1 t2) of(Yes prf1, Yes prf2) => Yes $ EquivHeadAndTail prf1 prf2(Yes prf1, No ctra2) => No $ fromNotEquivTail @{e} ctra2(No ctra1, _) => No $ fromNotEquivHead @{e} ctra1
import public Data.LinkedList.Equivalence
public export(Equivalence t) => Equivalence (LinkedList t) whereEquiv = LinkedListEquivdecEquiv = decLinkedListEquivpublic exportconcat : LinkedList t -> LinkedList t -> LinkedList tconcat Nil y = yconcat (x::xs) y = x :: concat xs y
import public Data.LinkedList.Group
public exportconcatNil : (l : LinkedList t) -> concat l Nil = lconcatNil Nil = ReflconcatNil (x::xs) = rewrite concatNil xs in Reflpublic exportMagma (LinkedList t) where(<>) = concatpublic exportSemigroup (LinkedList t) whereproofAssociative Nil _ _ = ReflproofAssociative (x::xs) y z = rewrite proofAssociative xs y z in Reflpublic exportMonoid (LinkedList t) whereid = NilproofLeftIdentity Nil = ReflproofLeftIdentity (x::xs) = rewrite Monoid.proofLeftIdentity xs in ReflproofRightIdentity Nil = ReflproofRightIdentity (y::ys) = rewrite Monoid.proofRightIdentity ys in Reflpublic exportFunctor LinkedList where_ <$> Nil = Nilf <$> (h::t) = f h :: f <$> tproofIdentity Nil = ReflproofIdentity (_::t) with (proofIdentity t)proofIdentity (_::_) | prf = rewrite prf in ReflproofComposition f g Nil = ReflproofComposition f g (_::t) = rewrite proofComposition f g t in Reflpublic exportapp : LinkedList (a -> b) -> LinkedList a -> LinkedList bapp Nil _ = Nilapp (f::fs) l = (f <$> l) <> app fs lpublic exportappNil : (f : LinkedList (a -> b)) -> f `app` Nil = NilappNil Nil = ReflappNil (f::fs) = rewrite appNil fs in Reflpublic exportApplicative LinkedList wherepure x = [x](<*>) = appproofIdentity Nil = ReflproofIdentity (_::xs) with (Functor.proofIdentity xs)proofIdentity (_::xs) | prf =rewrite concatNil (identity <$> xs) inrewrite prf in ReflproofHomomorphism f x = ReflproofInterchange Nil x = ReflproofInterchange (f::fs) x = rewrite proofInterchange fs x in ReflproofComposition Nil Nil _ = ReflproofComposition Nil (_::gs) _ =rewrite appNil gs in-- rewrite concatNil ((.) <$> gs) in?holeComposition1proofComposition (f::fs) gs _ =-- rewrite concatNil ((.) <$> gs) in?holeComposition2public exportMonad LinkedList whereNil >>= _ = Nil(x::xs) >>= f = f x <> (xs >>= f)proofLeftIdentity x f = rewrite concatNil (f x) in ReflproofRightIdentity Nil = ReflproofRightIdentity (x::xs) with (Monad.proofRightIdentity xs)proofRightIdentity (_::_) | prf = rewrite prf in ReflproofAssociative Nil f g = ReflproofAssociative (x::xs) f g with (f x)proofAssociative (x::xs) f g | Nil = rewrite proofAssociative xs f g in ReflproofAssociative (x::xs) f g | (r::rs) = ?holeAssociative
import public Data.LinkedList.Functorimport public Data.LinkedList.Applicativeimport public Data.LinkedList.Monad
module Data.LinkedList.Monadimport Builtinimport Algebra.Control.Applicativeimport Algebra.Control.Monadimport public Data.LinkedList.Basicimport public Data.LinkedList.Applicativepublic exportMonad LinkedList whereNil >>= _ = Nil(x::xs) >>= f = f x `concat` (xs >>= f)proofLeftIdentity x f = rewrite proofConcatRightIdentity (f x) in ReflproofRightIdentity Nil = ReflproofRightIdentity (x::xs) with (Monad.proofRightIdentity xs)proofRightIdentity (_::_) | prf = rewrite prf in ReflproofAssociative Nil f g = ReflproofAssociative (x::xs) f g = case f x ofNil => ?holeAssociative1(r::rs) => ?holeAssociative2
module Data.LinkedList.Groupimport Builtinimport Algebra.Group.Magmaimport Algebra.Group.Semigroupimport Algebra.Group.Monoidimport public Data.LinkedList.Basic%default totalpublic exportMagma (LinkedList t) where(<>) = concatpublic exportSemigroup (LinkedList t) whereproofAssociative Nil _ _ = ReflproofAssociative (x::xs) y z = rewrite proofAssociative xs y z in Reflpublic exportMonoid (LinkedList t) whereid = NilproofLeftIdentity Nil = ReflproofLeftIdentity (x::xs) = rewrite Monoid.proofLeftIdentity xs in ReflproofRightIdentity Nil = ReflproofRightIdentity (y::ys) = rewrite Monoid.proofRightIdentity ys in Refl
module Data.LinkedList.Functorimport Builtinimport Algebra.Control.Functorimport public Data.LinkedList.Basicpublic exportFunctor LinkedList where_ <$> Nil = Nilf <$> (h::t) = f h :: f <$> tproofIdentity Nil = ReflproofIdentity (_::t) with (proofIdentity t)proofIdentity (_::_) | prf = rewrite prf in ReflproofComposition f g Nil = ReflproofComposition f g (_::t) = rewrite proofComposition f g t in Refl
module Data.LinkedList.Equivalenceimport Builtinimport Algebra.Relation.Equivalenceimport public Data.LinkedList.Basic%default totalpublic exportdata LinkedListEquiv : Equivalence t => (a, b : LinkedList t) -> Type whereBothEmpty : (e : Equivalence t) => LinkedListEquiv @{e} Nil NilEquivHeadAndTail : (e : Equivalence t) => {a, b : t} -> {x, y : LinkedList t}-> (ok1: Equiv a b) -> (ok2: LinkedListEquiv x y)-> LinkedListEquiv @{e} (a :: x) (b :: y)public export(e : Equivalence a) => Uninhabited (LinkedListEquiv @{e} Nil (h :: t)) whereuninhabited BothEmpty impossibleuninhabited (EquivHeadAndTail h t) impossiblepublic export(e : Equivalence a) => Uninhabited (LinkedListEquiv @{e} (h :: t) Nil) whereuninhabited BothEmpty impossibleuninhabited (EquivHeadAndTail h t) impossiblepublic exportfromNotEquivHead : (e : Equivalence t) => {a, b : t} -> (ok: Not (Equiv a b))-> Not (LinkedListEquiv @{e} (a :: x) (b :: y))fromNotEquivHead ctr (EquivHeadAndTail prf _) = ctr prfpublic exportfromNotEquivTail : (e : Equivalence t) => (ok: Not (LinkedListEquiv @{e} x y))-> Not (LinkedListEquiv @{e} (a :: x) (b :: y))fromNotEquivTail ctr (EquivHeadAndTail _ prf) = ctr prfdecLinkedListEquiv : (e : Equivalence t) => (a, b : LinkedList t)-> Dec (LinkedListEquiv @{e} a b)decLinkedListEquiv Nil Nil = Yes BothEmptydecLinkedListEquiv Nil (_::_) = No absurddecLinkedListEquiv (_::_) Nil = No absurddecLinkedListEquiv @{e} (h1::t1) (h2::t2) =case (decEquiv @{e} h1 h2, decLinkedListEquiv t1 t2) of(Yes prf1, Yes prf2) => Yes $ EquivHeadAndTail prf1 prf2(Yes prf1, No ctra2) => No $ fromNotEquivTail @{e} ctra2(No ctra1, _) => No $ fromNotEquivHead @{e} ctra1public export(Equivalence t) => Equivalence (LinkedList t) whereEquiv = LinkedListEquivdecEquiv = decLinkedListEquiv
module Data.LinkedList.Basicimport Builtin%default totalinfixr 7 ::public exportdata LinkedList t = Nil | (::) t (LinkedList t)public exportconcat : LinkedList t -> LinkedList t -> LinkedList tconcat Nil y = yconcat (x::xs) y = x :: concat xs yexportproofConcatRightIdentity : (l : LinkedList t) -> concat l Nil = lproofConcatRightIdentity Nil = ReflproofConcatRightIdentity (x::xs) = rewrite proofConcatRightIdentity xs in Refl
module Data.LinkedList.Applicativeimport Builtinimport Algebra.Control.Functorimport Algebra.Control.Applicativeimport public Data.LinkedList.Basicimport public Data.LinkedList.Functor%default totalpublic exportapp : LinkedList (a -> b) -> LinkedList a -> LinkedList bapp Nil _ = Nilapp (f::fs) l = (f <$> l) `concat` app fs lpublic exportappNil : (f : LinkedList (a -> b)) -> f `app` Nil = NilappNil Nil = ReflappNil (f::fs) = rewrite appNil fs in Reflpublic exportApplicative LinkedList wherepure x = [x](<*>) = appproofIdentity Nil = ReflproofIdentity (_::xs) with (Functor.proofIdentity xs)proofIdentity (_::xs) | prf =rewrite proofConcatRightIdentity (identity <$> xs) inrewrite prf in ReflproofHomomorphism f x = ReflproofInterchange Nil x = ReflproofInterchange (f::fs) x = rewrite proofInterchange fs x in ReflproofComposition Nil Nil _ = ReflproofComposition Nil (_::gs) _ =rewrite appNil gs in-- rewrite proofConcatRightIdentity ((.) <$> gs) in?holeComposition1proofComposition (f::fs) gs _ =-- rewrite proofConcatRightIdentity ((.) <$> gs) in?holeComposition2