From 56bd43122383c4966253a5293e085a1903173df1 Mon Sep 17 00:00:00 2001 From: "ajeffrey@roblox.com" Date: Fri, 25 Mar 2022 17:53:04 -0500 Subject: [PATCH] Add RFC for Luau function and table types --- rfcs/function-and-table-types.md | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 rfcs/function-and-table-types.md diff --git a/rfcs/function-and-table-types.md b/rfcs/function-and-table-types.md new file mode 100644 index 00000000..f7ea5ca7 --- /dev/null +++ b/rfcs/function-and-table-types.md @@ -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.