UPDATE: My initial investigation into the bus this morning was incomplete and incorrect. The specification text for the first phase is correct. The implementation is correct.
The specification is incorrect in that the second order of events is incorrect. We must indicate that we are outputting the output type before correcting the independent parameters.
Man, this stuff is complicated. I have rewritten this section of the specification more times than I remember.
I have seen this problem before, and I clearly recall creating revisions, so the incorrect term "type variable" is everywhere replaced by "type parameter". (Type parameters are not storage locations whose contents may vary, so it makes no sense to call them variables.) I think at the same time I noticed that the order was incorrect. It probably happened that we accidentally sent an older version of the specification on the Internet. A lot of apologies.
I will work with Mads to update the specification in accordance with the implementation. I think that the correct formulation of the second phase should look something like this:
- If there are no parameters of an uncommitted type, then type inference succeeds.
- Otherwise, if there is one or more arguments Ei with the corresponding parameter type Ti such that the output type Ei with type Ti contains at least one uncommitted type of parameter Xj and none of the input types Ei with type Ti contains any uncommitted type of the parameter Xj, then the output of the output type is made from all such Ei in Ti.
Regardless of whether the previous step really concluded, we must now correct at least one type parameter, as shown below:
- If there is one or more parameters of type Xi such that Xi is not fixed and Xi has a nonempty set of estimates and Xi is independent of any Xj, then each such Xi is fixed. If any commit operation is not performed, type inference is not performed.
- Otherwise, if there is one or more parameters of type Xi such that Xi is unfixed and Xi has a nonempty set of estimates and there is at least one parameter of type Xj depending on Xi, then each such Xi is fixed. If any commit operation is not performed, type inference is not performed.
- Otherwise, we will not be able to make progress and uncommitted parameters. Type input error.
If type inference fails or fails, repeat the second phase.
The idea here is that we want to make sure that the algorithm never goes into an infinite loop. With each repetition of the second phase, he either succeeds, or fails, or makes progress. It cannot loop more than once there are type parameters for type correction.
Thank you for bringing this to my attention.
Eric Lippert Sep 13 '10 at 14:23 2010-09-13 14:23
source share