mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add RFC for Luau function and table types
This commit is contained in:
parent
2c339d52c0
commit
56bd431223
1 changed files with 35 additions and 0 deletions
35
rfcs/function-and-table-types.md
Normal file
35
rfcs/function-and-table-types.md
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Add primitive function and table types
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Add types for "real" functions and tables.
|
||||||
|
|
||||||
|
## Motivation
|
||||||
|
|
||||||
|
Some APIs require "real" functions and tables, not just things that
|
||||||
|
"look functiony" (e.g. tables with a `__call__` metamethod) or "look
|
||||||
|
tabley" (e.g. instances of classes). This RFC adds types for those.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
Add:
|
||||||
|
|
||||||
|
* a type `table`, inhabited by Luau tables (but not class instances), and
|
||||||
|
* a type `function`, inhabited by Luau functions (but not class methods or
|
||||||
|
tables with metamethods).
|
||||||
|
|
||||||
|
Luau functions with known source and targe types are now an intersection type `function & (T) -> U`.
|
||||||
|
|
||||||
|
Luau tables with known properties are now an intersection type `table & { p : T }`.
|
||||||
|
|
||||||
|
We may want to provide syntax sugar `function(T) -> U` and `table{ p : T }` for these, since they will probably be quite common.
|
||||||
|
|
||||||
|
We should audit APIs to see which ones accept functiony or tably arguments, and which ones want real functions and tables.
|
||||||
|
|
||||||
|
## Drawbacks
|
||||||
|
|
||||||
|
Another bit of complexity budget spent.
|
||||||
|
|
||||||
|
## Alternatives
|
||||||
|
|
||||||
|
Stick with the current imprecision.
|
Loading…
Add table
Reference in a new issue