Invariant Generation as Type Inference with GADTs and Existentials