Test of lock and key system

This commit is contained in:
2021-11-22 23:54:58 +00:00
parent 05e1307336
commit 5ab5be3087
11 changed files with 84 additions and 20 deletions
+11 -1
View File
@@ -7,19 +7,29 @@ module Dodge.Tree.Compose
, chainUses
, useAllAtEnd
, changeToPassDown
, overwriteLabel
) where
import Dodge.Tree.Compose.Data
import Dodge.Tree.Polymorphic
import Data.Tree
expandTree :: CompTree a -> Tree a
expandTree (Node root extChildren) = case root of
Node (UseAll x) _ -> Node x (map expandTree extChildren)
Node (UseSome is x) _ -> Node x (map (expandTree . \i -> extChildren !! i) is)
Node (UseNone _) _ -> fmap _unCompose root
Node (UseNone _) _ -> fmap _unCompose root
Node (UseLabel _ _) _ -> fmap _unCompose root
Node (PassDown x) xs -> Node x $ map (expandTree . (`Node` extChildren)) xs
Node (SplitDown x) xs -> Node x $ map expandTree $ zipWith Node xs
$ map (:[]) extChildren ++ repeat []
overwriteLabel :: Int -> (a -> ComposingNode a) -> SubCompTree a -> [SubCompTree a] -> SubCompTree a
overwriteLabel i f t ts = head $ updateSingleNode islabel update t
where
islabel (UseLabel j _) | i == j = True
islabel _ = False
update (Node cr _) = Node (f $ _unCompose cr) ts
passUntilUseAll :: SubCompTree a -> [SubCompTree a] -> SubCompTree a
passUntilUseAll (Node (UseAll x) _) ts' = Node (PassDown x) ts'
passUntilUseAll (Node cn ts) ts' = Node (PassDown (_unCompose cn)) $ map (`passUntilUseAll` ts') ts