5 | ||| Generalisation of Rose trees with a container of subtrees instead of
6 | ||| a list of subtrees. It's required that the container is a TensorMonoid
11 | ||| Same as above, but with data stored at nodes
16 | ||| Same as above, but with data stored at leaf
21 | ||| Rose trees with data stored at both nodes and leaves
26 | ||| Rose trees with data stored at nodes
31 | ||| Rose trees with data stored at leaves
37 | {-
38 | old rose tree implementation
39 | namespace RoseTrees
40 | ||| Rose tree, a tree with a variable number of children.
41 | ||| This can likely be generalised to other Applicatives than List
42 | public export
43 | data RoseTreeShape : Type where
44 | LeafS : RoseTreeShape
45 | NodeS : List RoseTreeShape -> RoseTreeShape
47 | %runElab derive "RoseTreeShape" [Eq, Show]
48 | %name RoseTreeShape t, t1, t2, t3
50 | public export
51 | numLeaves : RoseTreeShape -> Nat
52 | numLeaves LeafS = 1
53 | numLeaves (NodeS ts) = sum (numLeaves <$> ts)
55 | public export
56 | numNodes : RoseTreeShape -> Nat
57 | numNodes LeafS = 0
58 | numNodes (NodeS ts) = 1 + sum (numNodes <$> ts)
60 | namespace NodesAndLeaves
61 | ||| Positions corresponding to both nodes and leaves within a RoseTreeShape
62 | public export
63 | data RoseTreePos : (t : RoseTreeShape) -> Type where
64 | AtLeaf : RoseTreePos LeafS
65 | AtNode : {ts : List RoseTreeShape} -> RoseTreePos (NodeS ts)
66 | SubTree : {ts : List RoseTreeShape} ->
67 | (i : Fin (length ts)) -> -- which subtree
68 | RoseTreePos (index' ts i) -> -- position in that subtree
69 | RoseTreePos (NodeS ts)
71 | -- For some reason the line below breaks?
72 | -- %runElab deriveIndexed "RoseTreePos" [Eq, Show]
74 | namespace Nodes
75 | ||| Positions corresponding to internal nodes within a RoseTreeNode shape.
76 | public export
77 | data RoseTreePosNode : (t : RoseTreeShape) -> Type where
78 | Done : {ts : List RoseTreeShape} -> RoseTreePosNode (NodeS ts)
79 | SubTree : {ts : List RoseTreeShape} ->
80 | (i : Fin (length ts)) -> -- which subtree
81 | RoseTreePosNode (index' ts i) -> -- position in that subtree
82 | RoseTreePosNode (NodeS ts)
84 | -- %runElab deriveIndexed "RoseTreePosNode" [Eq, Show]
86 | namespace Leaves
87 | ||| Positions corresponding to leaves within a RoseTreeLeaf shape.
88 | public export
89 | data RoseTreePosLeaf : (t : RoseTreeShape) -> Type where
90 | Done : RoseTreePosLeaf LeafS
91 | SubTree : {ts : List RoseTreeShape} ->
92 | (i : Fin (length ts)) -> -- which subtree
93 | RoseTreePosLeaf (index' ts i) -> -- position in that subtree
94 | RoseTreePosLeaf (NodeS ts)
96 | -- %runElab deriveIndexed "RoseTreePosLeaf" [Eq, Show]
97 | -}