0 | module Data.Container.Base.InstanceInterfaces
3 | import Decidable.Equality
4 | import Data.Fin.Split
8 | import Data.Container.Base.Object.Definition
9 | import Data.Container.Base.Extension.Definition
10 | import Data.Container.Base.Concrete.Definition
11 | import Data.Container.Base.Object.Instances
12 | import Data.Container.Base.Extension.Instances
13 | import Data.Container.Base.Concrete.Instances
16 | import Data.Container.Base.TreeUtils
17 | import Data.Functor.Algebra
20 | %hide Prelude.toList
27 | (c : Cont) -> (isFinite : IsFinite c) =>
28 | (0 a : Type) -> Num a =>
30 | algebraFinite c {isFinite = MkI @{p}} _
31 | = MkAlgebra $
\(shp <| content) => reduce $
values @{p shp} <&> content
33 | namespace VectInstances
35 | {n : Nat} -> Eq x => Eq (Vect' n x) where
36 | v == v' = (toVect v) == (toVect v')
39 | {n : Nat} -> Show x => Show (Vect' n x) where
40 | show v = show (toVect v)
43 | {n : Nat} -> Foldable (Vect' n) where
44 | foldr f z v = foldr f z (toVect v)
47 | {n : Nat} -> Num a => Algebra (Vect' n) a where
48 | reduce v = reduce (toVect v)
51 | {n : Nat} -> Traversable (Vect' n) where
52 | traverse f v = fromVect <$> traverse f (toVect v)
59 | (s : Fin (S n)) -> Vect' n a -> Vect' (finToNat s) a
60 | take s = fromVect . takeFin s . toVect
63 | (++) : {n : Nat} -> Vect' n a -> Vect' m a -> Vect' (n + m) a
64 | (++) v1 v2 = () <| \i => case splitSum i of
65 | Left i1 => index v1 i1
66 | Right i2 => index v2 i2
73 | namespace ListInstances
76 | Eq a => Eq (List' a) where
77 | l == l' = assert_total ((toList l) == (toList l'))
81 | Show a => Show (List' a) where
82 | show x = assert_total (show (toList x))
85 | Foldable List' where
86 | foldr f z v = foldr f z (toList v)
89 | Num a => Algebra List' a where
90 | reduce = reduce {f=List} . toList
107 | namespace BinTreeInstances
110 | Eq a => Eq (BinTree' a) where
111 | t == t' = assert_total (toBinTreeSame t == toBinTreeSame t')
115 | Show a => Show (BinTree' a) where
116 | show = assert_total (show . toBinTreeSame)
120 | Num a => Algebra BinTree' a where
121 | reduce = reduce {f=BinTreeSame} . toBinTreeSame
128 | namespace BinTreeLeafInstances
131 | Eq a => Eq (BinTreeLeaf' a) where
132 | t == t' = assert_total (toBinTreeLeaf t == toBinTreeLeaf t')
136 | Show a => Show (BinTreeLeaf' a) where
137 | show = assert_total (show . toBinTreeLeaf)
141 | Num a => Algebra BinTreeLeaf' a where
142 | reduce = reduce {f=BinTreeLeaf} . toBinTreeLeaf
146 | Foldable BinTreeLeaf' where
147 | foldr f z t = foldr {t=BinTreeLeaf} f z (toBinTreeLeaf t)
150 | namespace BinTreeNodeInstances
153 | Eq a => Eq (BinTreeNode' a) where
154 | t == t' = assert_total (toBinTreeNode t == toBinTreeNode t')
158 | Show a => Show (BinTreeNode' a) where
159 | show = assert_total (show . toBinTreeNode)
163 | Num a => Algebra BinTreeNode' a where
164 | reduce = reduce {f=BinTreeNode} . toBinTreeNode