Added retyping tree maps

Incorporated commits from #144. The logic here is very similar, modulo some minor
organization and naming changes. The only deeper difference concerns retypeSelect,
which here makes use of derivedSelect without changing kinds of tree nodes.