-
Notifications
You must be signed in to change notification settings - Fork 113
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
generalize internal representation of generic types #890
Conversation
Teal Playground URL: https://890--teal-playground-preview.netlify.app |
I just saw two issues already when running the LuaRocks codebase through it: Error 1) modules that return a generic type
https://github.com/luarocks/luarocks/blob/master/src/luarocks/search.tl#L16 Error 2) and a stricter resolution of type arguments (which I need to look closer, but might be a legitimate error that it has now caught)
https://github.com/luarocks/luarocks/blob/master/src/luarocks/search.tl#L16 |
aaceca7
to
8cdb640
Compare
Error 1 there was being misreported (it was being reported at the wrong location). It was a legitimate error, a missing Error 2 is a bit trickier because it is a type check that we would like to accept (because we know that |
All types that have type variables are now represented as a GenericType record, which holds a non-generic Type and an array of type arguments. This change is because originally we only cared about generic records and generic functions, but once we have the `local type MyType<T> = ...` syntax, other types can be generic as well (in particular, unions). Instead of replicating generic support logic in the implementation of each type, we factor it out into a type-level term which encapsulates the application of type variables, which is something more like second-order lambda calculus. See https://en.wikipedia.org/wiki/System_F and the ensuing rabbit hole.
See #891 and test cases for description.
8cdb640
to
00c1d71
Compare
All right, I decided to do the brave thing and merge this already. The fixes contained here are important enough so that it's clear that this should be the baseline moving forward. If this has introduced any further regressions, then let's fix it in the main branch. |
All types that have type variables are now represented as a GenericType record, which holds a non-generic Type and an array of type arguments.
This change is because originally we only cared about generic records and generic functions, but once we have the
local type MyType<T> = ...
syntax, other types can be generic as well (in particular, unions).Instead of replicating generic support logic in the implementation of each type, we factor it out into a type-level term which encapsulates the application of type variables, which is something more like second-order lambda calculus.
(See https://en.wikipedia.org/wiki/System_F and the ensuing rabbit hole.)
Fixes #880.
Fixes #787.