Fix var type inference2

Taking a second approach where I'm trying to infer the most general sort that fits in a particular context.

Let's see if tests pass first.