Various fixes related to literals and type inference. Move some utility methods over from optiq.