further refactor Infer.hs