Closed davidweichiang closed 1 year ago
Definitely a bug:
define double = \x. (x, x);
let (f, g) = double (\y. y) in f ()
-z
gives [0.0]
, which is not right.
I think the problem is that when a function definition is typechecked, we need to record whether each \forall-quantified type variable needs to be constrained to be Robust. Then when infer' instantiates a \forall-quantified type variable to a fresh one, it needs to add a Robust constraint if needed. This information can be stored in a few possible places:
newtype TypeVar = String
; this could become data TypeVar = TvAny | TvRobust
.RobustIf x y
where x is the \forall-quantified type variable and y is the fresh one. The meaning is if there is a constraint Robust x
then y
must also be robust. Then solvedWell can make two passes through the list of constraints, first collecting all the Robust
constraints, then checking the RobustIf
constraints.I don't think 2 or 4 will work, since the constraints are not retained across SCCs. So maybe 3? @ccshan, are you trying to split Var into multiple types?
infer'
had access to the function definitions, it could just check whether the definition uses each parameter twice.
This does not cause an error (even with -O0):
However, these do: