21 | ||| Generalisation of Rose trees with a container of subtrees instead of
22 | ||| a list of subtrees. It's required that the container is a TensorMonoid
27 | ||| Same as above, but with data stored at nodes
32 | ||| Same as above, but with data stored at leaf
37 | ||| Rose trees with data stored at both nodes and leaves
42 | ||| Rose trees with data stored at nodes
47 | ||| Rose trees with data stored at leaves
53 | {-
54 | old rose tree implementation
55 | namespace RoseTrees
56 | ||| Rose tree, a tree with a variable number of children.
57 | ||| This can likely be generalised to other Applicatives than List
58 | public export
59 | data RoseTreeShape : Type where
60 | LeafS : RoseTreeShape
61 | NodeS : List RoseTreeShape -> RoseTreeShape
63 | %runElab derive "RoseTreeShape" [Eq, Show]
64 | %name RoseTreeShape t, t1, t2, t3
66 | public export
67 | numLeaves : RoseTreeShape -> Nat
68 | numLeaves LeafS = 1
69 | numLeaves (NodeS ts) = sum (numLeaves <$> ts)
71 | public export
72 | numNodes : RoseTreeShape -> Nat
73 | numNodes LeafS = 0
74 | numNodes (NodeS ts) = 1 + sum (numNodes <$> ts)
76 | namespace NodesAndLeaves
77 | ||| Positions corresponding to both nodes and leaves within a RoseTreeShape
78 | public export
79 | data RoseTreePos : (t : RoseTreeShape) -> Type where
80 | AtLeaf : RoseTreePos LeafS
81 | AtNode : {ts : List RoseTreeShape} -> RoseTreePos (NodeS ts)
82 | SubTree : {ts : List RoseTreeShape} ->
83 | (i : Fin (length ts)) -> -- which subtree
84 | RoseTreePos (index' ts i) -> -- position in that subtree
85 | RoseTreePos (NodeS ts)
87 | -- For some reason the line below breaks?
88 | -- %runElab deriveIndexed "RoseTreePos" [Eq, Show]
90 | namespace Nodes
91 | ||| Positions corresponding to internal nodes within a RoseTreeNode shape.
92 | public export
93 | data RoseTreePosNode : (t : RoseTreeShape) -> Type where
94 | Done : {ts : List RoseTreeShape} -> RoseTreePosNode (NodeS ts)
95 | SubTree : {ts : List RoseTreeShape} ->
96 | (i : Fin (length ts)) -> -- which subtree
97 | RoseTreePosNode (index' ts i) -> -- position in that subtree
98 | RoseTreePosNode (NodeS ts)
100 | -- %runElab deriveIndexed "RoseTreePosNode" [Eq, Show]
102 | namespace Leaves
103 | ||| Positions corresponding to leaves within a RoseTreeLeaf shape.
104 | public export
105 | data RoseTreePosLeaf : (t : RoseTreeShape) -> Type where
106 | Done : RoseTreePosLeaf LeafS
107 | SubTree : {ts : List RoseTreeShape} ->
108 | (i : Fin (length ts)) -> -- which subtree
109 | RoseTreePosLeaf (index' ts i) -> -- position in that subtree
110 | RoseTreePosLeaf (NodeS ts)
112 | -- %runElab deriveIndexed "RoseTreePosLeaf" [Eq, Show]
113 | -}
116 | ||| Isomorphic to Data.Tree.ApplicativeRoseTree (TODO)
130 | ||| Isomorphic to Data.Tree.RoseTree
135 | ||| Isomorphic to Data.Tree.RoseTreeNode (TODO)
140 | ||| Isomorphic to Data.Tree.RoseTreeLeaf (TODO)
156 | rw2 : (shapeExt (index t (rewrite sym (mapShapeExt {f=shapeExt} t) in ps)) = index (shapeExt <$> t) ps) := mapIndexCont {c=List} {f=shapeExt} t ps
160 | -- for some reason all the explicit type annotations above are needed
161 | -- to convince the typechecker
180 | ||| In `Data.Tree` we have analogos maps that need to be translated here
191 | -- Node version likely does not exist?
197 | -- public export
198 | -- ApplicativeRoseTree : ContA -> ContA
199 | -- ApplicativeRoseTree c = (#) (ApplicativeRoseTree c)
202 | -- namespace RoseTreeInstances
203 | -- -- TODO this should be superseeded by the general applicative instance above?
204 | -- public export
205 | -- liftA2RoseTree' : RoseTree' a -> RoseTree' b -> RoseTree' (a, b)
206 | -- liftA2RoseTree' t1 t2 = fromRoseTreeSame $
207 | -- liftA2RoseTreeSame (toRoseTreeSame t1) (toRoseTreeSame t2)
208 | --
209 | -- public export
210 | -- Applicative RoseTree' where
211 | -- pure a = LeafS <| \_ => a
212 | -- fs <*> vs = uncurry ($) <$> liftA2RoseTree' fs vs