entrytree_tag :: Entry a => [EntryTree a] -> Loc -> TagAction -> Maybe [EntryTree a]
entrytree_tag et loc what =
    entrytree_map_path f et loc
    where
        f e Nothing eloc | loc==eloc =
            case (entrytree_tagged e, what) of
                (False, TagSet) -> Just [e{entrytree_tagged=True}]
                (False, TagToggle) -> Just [e{entrytree_tagged=True}]
                (True, TagUnset) -> Just [e{entrytree_tagged=False}]
                (True, TagToggle) -> Just [e{entrytree_tagged=False}]
                otherwise -> Nothing
        f e (Just nch) _ =
            Just [e{entrytree_children = nch}]
        f _ _ _ = Nothing
entrytree_tag :: Entry a => [EntryTree a] -> Loc -> TagAction -> Maybe [EntryTree a]
entrytree_tag et loc what =
    entrytree_map_path f et loc
    where
        f e Nothing eloc | loc==eloc =
            case (entrytree_tagged e, what) of
                (False, TagSet) -> Just [e{entrytree_tagged=True}]
                (False, TagToggle) -> Just [e{entrytree_tagged=True}]
                (True, TagUnset) -> Just [e{entrytree_tagged=False}]
                (True, TagToggle) -> Just [e{entrytree_tagged=False}]
                otherwise -> Nothing
        f e (Just nch) _ =
            Just [e{entrytree_children = nch}]
        f _ _ _ = Nothing
entrytree_tag et loc what =
    entrytree_map_path f et loc
    where
        f e Nothing eloc | loc==eloc =
            case (entrytree_tagged e, what) of
                (False, TagSet) -> Just [e{entrytree_tagged=True}]
                (False, TagToggle) -> Just [e{entrytree_tagged=True}]
                (True, TagUnset) -> Just [e{entrytree_tagged=False}]
                (True, TagToggle) -> Just [e{entrytree_tagged=False}]
                otherwise -> Nothing
        f e (Just nch) _ =
            Just [e{entrytree_children = nch}]
        f _ _ _ = Nothing