A more complete port of HindleyMilner.scala