Fixing a type variable inside a function