0 | module Data.Container.Base.Extension.Instances
5 | import Data.Container.Base.Object.Definition
6 | import Data.Container.Base.Extension.Definition
7 | import Data.Container.Base.Properties.Definition
9 | import Data.Container.Base.Object.Instances
10 | import Data.Container.Base.Product.Definition
17 | namespace ExtensionsOfMainExamples
20 | Scalar' : Type -> Type
21 | Scalar' = Ext Scalar
25 | Pair' : Type -> Type
30 | Either' : Type -> Type
31 | Either' = Ext Either
35 | Maybe' : Type -> Type
40 | List' : Type -> Type
45 | Vect' : (n : Nat) -> Type -> Type
46 | Vect' n = Ext (Vect n)
50 | Stream' : Type -> Type
51 | Stream' = Ext Stream
55 | BinTree' : Type -> Type
56 | BinTree' = Ext BinTree
60 | BinTreeNode' : Type -> Type
61 | BinTreeNode' = Ext BinTreeNode
65 | BinTreeLeaf' : Type -> Type
66 | BinTreeLeaf' = Ext BinTreeLeaf
81 | composeExtensions : List Cont -> Type -> Type
82 | composeExtensions = foldr (\c, f => (Ext c) . f) (Ext Scalar)
84 | namespace ComposeExtensionsVect
86 | composeExtensions : Vect n Cont -> Type -> Type
87 | composeExtensions = foldr @{straightforward} (\c, f => (Ext c) . f) (Ext Scalar)
90 | [fe] {shape : List Cont} -> Functor (composeExtensions shape) where
91 | map {shape = []} f = map f
92 | map {shape = (s :: ss)} f = (map @{fe} f <$>)
95 | EmptyExt : {0 c : Cont} -> IsNaperian c => Ext c Unit
96 | EmptyExt @{MkIsNaperian _} = () <| \_ => ()
99 | liftA2ConstCont : IsNaperian c => Ext c a -> Ext c b -> Ext c (a, b)
100 | liftA2ConstCont @{MkIsNaperian _} ea eb = () <| (\x => (index ea x, index eb x))
106 | IsNaperian c => Applicative (Ext c) where
107 | pure @{MkIsNaperian _} a = () <| \_ => a
108 | (<*>) fs xs @{MkIsNaperian _} = uncurry ($) <$> liftA2ConstCont fs xs
115 | positionsCont : {0 c : Cont} -> {sh : c.Shp} -> Ext c (c.Pos sh)
116 | positionsCont = sh <| id
122 | set : InterfaceOnPositions c Eq =>
123 | (e : Ext c x) -> c.Pos (shapeExt e) -> x -> Ext c x
124 | set {c=(s !> p)} @{MkI _} (sh <| contentAt) i x
125 | = sh <| updateAt contentAt (i, x)