-
Notifications
You must be signed in to change notification settings - Fork 2
Luau Implementation #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
ed8a98a
3b84dbc
6286569
0b6e139
ddb23b0
d6b2b4f
50fb6e0
5082311
5b1d99d
2618f09
3d0926c
3efef30
2e00579
0f9917e
7cbaa13
fca979d
ab2995b
957286e
a2fd4cb
1cf0bc3
4fd8bac
67cec98
00d49ec
c6dd1d9
da09d05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Luau | ||
|
||
Luau is a typed-sister variant of Lua (it breaks backwards compatibility after | ||
v5.1). | ||
|
||
- Language resources: | ||
- <https://www.luau.org/> | ||
- <https://github.com/luau-lang/luau/> | ||
- If-T version: **1.0** | ||
- Implementation: [main.luau](main.luau) | ||
|
||
#### Type System Basics | ||
|
||
> Q. What is the top type in this language? What is the bottom type? What is the | ||
> dynamic type? If these types do not exist, explain the alternatives. | ||
|
||
- Top = `unknown` | ||
- Bottom = `never` | ||
- Dynamic = `any` | ||
|
||
> Q. What base types does this implementation use? Why? | ||
|
||
It uses `string`,`number` and `boolean`. | ||
|
||
> Q. What container types does this implementation use (for objects, tuples, | ||
> etc)? Why? | ||
|
||
A Table in Luau is the base data structure for constructing complex objects or | ||
organizing data. This implementation adopts `tables` for Lists, Structs and to | ||
construct aliases for `Pairs` and `Tuples`. | ||
|
||
#### Type Narrowing | ||
|
||
> Q. How do simple type tests work in this language? | ||
|
||
Example: `typeof(x) == "number"` | ||
|
||
> Q. Are there other forms of type test? If so, explain. | ||
|
||
Yes, It also supports `IsA` and `is` for instance refinements. Assertions | ||
(`assert`) can also trigger type refinement. | ||
|
||
Example: `local x = Instance.new(Part); x:IsA("BasePart"); x:is("string")`\ | ||
Example: `assert(type(stringOrNumber) == "string")` | ||
|
||
> Q. How do type casts work in this language? | ||
|
||
Type casts are done with the double colon (`::`) syntax. | ||
|
||
Example: `x::number` | ||
|
||
> Q. What is the syntax for a symmetric (2-way) type-narrowing predicate? | ||
|
||
Luau does not supports these predicates yet. | ||
|
||
> Q. If the language supports other type-narrowing predicates, describe them | ||
> below. | ||
|
||
#### Benchmark Details | ||
|
||
> Q. Are any benchmarks inexpressible? Why? | ||
|
||
Luau is unable to express the type-narrowing predicate examples. The new solver | ||
supports | ||
[type functions](https://rfcs.luau.org/user-defined-type-functions.html), which | ||
should be ideal for implementing this, however, parameters are not allowed to be | ||
referenced in the return type. | ||
|
||
``` | ||
type function isString(T) | ||
return types.singleton(T:is("string")) | ||
end | ||
|
||
-- luau flags both instances of x in the signature as being in different scopes | ||
function predicate_2way_success_f(x: string | number): isString<x> | ||
return typeof(x) == "string" | ||
end | ||
``` | ||
|
||
> Q. Are any benchmarks expressed particularly well, or particularly poorly? | ||
> Explain. | ||
|
||
dibrinsofor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
define f(x: String | Number | Boolean) -> x is String: | ||
return x is String | ||
``` | ||
|
||
Since Luau, does not currently provide a direct way to connect a function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete the comma |
||
parameter to its returned type information in this manner, all the related | ||
examples (`predicate_checked`, `predicate_1way` and `predicate_2way`) are | ||
currently inexpressible. | ||
|
||
> Q. How direct (or complex) is the implementation compared to the pseudocode | ||
> from If-T? | ||
|
||
Very similar. Luau has some special syntax to get the length of some sequence or | ||
iterable. Other notable mentions are `~=` for the not operator and `_` as a | ||
prefix to silence warnings to unused definitions. | ||
|
||
Example: `#x` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this code example right below the sentence about length. It's not clear up above what the syntax actually is for getting the length of an iterable. |
||
|
||
It also supports special syntax for string concatenation. | ||
|
||
Example: `"Hello" .. "World"` | ||
|
||
#### Advanced Examples | ||
|
||
> Q. Are any examples inexpressible? Why? | ||
|
||
No. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR doesn't implement the examples! Either add an implementation and update this section, or replace the answers here with "N/A: the examples are future work.". |
||
|
||
> Q. Are any examples expressed particularly well, or particularly poorly? | ||
> Explain. | ||
|
||
No. | ||
|
||
> Q. How direct (or complex) is the implementation compared to the pseudocode | ||
> from If-T? | ||
|
||
Very similar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pairs
andTuples
should bePair
andTriple