From 4d6d2558934bbc7317d46d1c41e83f7d2df96ec3 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 18 Dec 2024 11:39:52 +0000 Subject: [PATCH] Add file --- src/Dodge/Data/MetaTree.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Dodge/Data/MetaTree.hs diff --git a/src/Dodge/Data/MetaTree.hs b/src/Dodge/Data/MetaTree.hs new file mode 100644 index 000000000..04ab56f29 --- /dev/null +++ b/src/Dodge/Data/MetaTree.hs @@ -0,0 +1,25 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module Dodge.Data.MetaTree where + +import Control.Lens +import Data.Tree + +data MetaTree a b = MTree + {_mtLabel :: b, _mtTree :: MetaNode a b, _mtBranches :: [MetaBranch a b]} + +data MetaNode a b + = NodeTree {_nodeTree :: Tree a} + | NodeMTree {_nodeMetaTree :: MetaTree a b} + +data MetaBranch a b = MBranch {_mbAttach :: a -> Maybe a, _mbTree :: MetaTree a b} + +newtype SelfTree a = ST {_unST :: Tree (a, Either (Tree a) (SelfTree a))} + +makeLenses ''MetaTree +makeLenses ''MetaBranch +makeLenses ''MetaNode + +instance Functor (MetaTree a) where + fmap f (MTree b mn bs) = MTree (f b) (mn & nodeMetaTree %~ fmap f) (map (mbTree %~ fmap f) bs)