make matched vars subtree-only
Parameterise environments by key type
Revert parametrisation of environments, use Object instead
Fix generics issues
Various changes to make pattern build work