-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contravariance of Lwt resolvers is unsound #458
Comments
I think we should mark this function deprecated, and either remove it in 4.0.0, or tell users that if they use I don't actually have any example where contravariance of resolvers is necessary. However, not having them contravariant suggests some kind of big misconception in Lwt, and doesn't match the expectations of people with some type theory background. Another thing that suggests deleting or discouraging use of @Drup, @hcarty, @raphael-proust, anyone else, any thoughts on this? |
Note that once the removal of float array optim has landed properly, the typechecker will be able to generalize contravariant variables just like covariant ones. Not sure if it's actually useful for |
Ok, I marked the function deprecated. I decided to save marking resolvers contravariant for 4.0.0. It's some kind of "co-breaking" change. While it shouldn't break any existing code that already compiles, it might break the assumptions of some programmers in a nasty way when writing new code or refactoring. |
It is not that |
@ivg, perhaps I come from a slightly different background, where variance is determined by elimination forms, of which With that perspective, the full statement is " |
And just to clarify, when either one of us says " |
What is unsound in So Besides, Perhaps, instead of deprecating |
To clarify, the type is defined by its definitions, thus the set of eliminators is fixed:
The idea was, that only the |
Normally, yes, but:
Or, in other terms, the abuse going on in |
...a.k.a. the typing connection between the constructors and basic operations in |
Yep. magic breaks everything, I agree. What I'm trying to say, is that it is not a variance of the type variable in |
Fortunately, they don't have a variance annotation in
lwt.mli
. However, they do inlwt.ml
, and there appears to have been the intent to make resolvers contravariant in the past (363f67a).I think they actually were contravariant at that point (I haven't looked at what the whole interface was back then). However, about 1.5 years later,
Lwt.waiter_of_wakener
was added (d996472), making possible the following interaction if resolvers are declared astype -'a u
:This prints
got `Foo
. Presumably, the compiler optimizes away the pattern-matching.Going by only the commit messages, it looks like not marking resolvers contravariant in the interface was an oversight, but it turned into a happy accident when
Lwt.waiter_of_wakener
was added – but of course, I don't know if this was intentional from the beginning, etc. @vouillon, @diml, any relevant background on any of this?The text was updated successfully, but these errors were encountered: