entrytree_insert et (LastUnder loc) eins =
    g $ entrytree_replace_f et loc f
    where
        f e = ([e{entrytree_children = ch ++ eins}], length ch)
              where
                  ch = entrytree_children e
        g (et, nch) = (et, loc_lastunder loc nch)


-- Remove

-- location list must be reverse-sorted for entrytree_remove_
entrytree_insert et (LastUnder loc) eins =
    g $ entrytree_replace_f et loc f
    where
        f e = ([e{entrytree_children = ch ++ eins}], length ch)
              where
                  ch = entrytree_children e
        g (et, nch) = (et, loc_lastunder loc nch)


-- Remove

-- location list must be reverse-sorted for entrytree_remove_
entrytree_insert et (LastUnder loc) eins =
    g $ entrytree_replace_f et loc f
    where
        f e = ([e{entrytree_children = ch ++ eins}], length ch)
              where
                  ch = entrytree_children e
        g (et, nch) = (et, loc_lastunder loc nch)


-- Remove

-- location list must be reverse-sorted for entrytree_remove_