-
Notifications
You must be signed in to change notification settings - Fork 469
Support coercing on a function type #6821
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
Comments
One observation: the coercion in the example seems to work if the argument type is not polymorphic, e.g. |
Ah, that makes sense. Unfortunately the way I'm trying to use it with Array sort requires polymorphism. For now I've just used an obj magic. |
See #6821 Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time. There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt. This just marks the place where one could investigate.
See #6821 Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time. There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt. This just marks the place where one could investigate.
See #6821 Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time. There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt. This just marks the place where one could investigate.
@TheSpyder any more tests for #6828 ? |
@cristianoc the second example is the one I pulled from my codebase, I haven't come across any others (although I haven't really been looking). I appreciate you looking at this! |
Great, that example is covered already. |
* Test: allow free vars in types for coercion. See #6821 Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time. There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt. This just marks the place where one could investigate. * Add tests of type coercion with free vars. * Clean up code for coercion and free variables. * Update CHANGELOG.md * Remove unused code for self coercion. * Remove unused error that suggests double coercion.
Done in #6828 |
I recently discovered that coercion works for variants where everything is represented by the same primitive type:
https://rescript-lang.org/docs/manual/latest/variant#coercing-variants-to-primitives
This is great, but I have a function that returns one of these variants and I can't coerce that. It seems to work for no-argument functions, but not functions with arguments.
https://rescript-lang.org/try?version=v11.1.1&code=C4TwDgpgBAhgzgSQHbCgXigHygAXgCgEYBKKAeSWmzznwCZSAVAdwHstcCBmJgCwCcIEAFDCANhFStKyYAC5YiFOnKVxkqMFayV+aRB1yAfFACWKYqImpBwAK78ksgKpJTqDPlJoTFEdahbBycUAGVzAHMJXQB9b181dVQtWQAxQl0gxxc3VGMofDtc9BNzYGJLAJSUVLpMyWDZcKQo6Hz8AHIYErMLYiA
The specific example I'm trying to model is array sort, so I'd need it to work on 2-argument functions as well.
https://rescript-lang.org/try?version=v11.1.1&code=C4TwDgpgBAxg9gWzAQwE4EsDOcB2UC8AUFFAD5QACymAFALQCMAlFADISaYAqAFsjsTKVqNAAwsAogEcArsgA2g8lVrMoAcVQRkwCKl79ChOJDwApTADoAgqlTIQAJkLyIwKNlTv8UGmlQANFAAfgBmAFy+AOTIQTEs+AB8sIgoGNg4CYmCnsAAkjgACvLIMBAA6ujAPH52dImY8uhlAGKoiGJMQTShUOHJ6DjATExAA
The text was updated successfully, but these errors were encountered: