Typed

Rewrite type checker to make it tidier.
Re-enable REFG to make recursion work.
Temporary drop support for generic functions.