Skip to content
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

Rework struct initializers #36

Open
Tracked by #45
Victorious3 opened this issue Nov 17, 2023 · 0 comments
Open
Tracked by #45

Rework struct initializers #36

Victorious3 opened this issue Nov 17, 2023 · 0 comments

Comments

@Victorious3
Copy link
Contributor

Victorious3 commented Nov 17, 2023

To avoid some ambiguity in the grammar and being able to use {} for blocks only, it's probably a good idea to change struct initializers to use the [] syntax.

The type of [] would depend on the elements provided.

Element Kind Resulting type
1 [] empty tuple ()
2 [1, 2, 3] static array [3; int]
3 [1, 2.0, 3] tuple (int, double, int)
4 [b = 20] structure struct { b: int }
5 [1, 2, b = 20] initializer Initializer([2; int], struct { b: int })
6 [1, 1.5, b = 20] initializer (jagged) Initializer((int, double), struct { b: int })
7 [(1) = 20, (2) = 30] initializer map InitializerMap([2; int], [2; int])
8 [(1) = 20, (1.5) = 2.5] initializer map (jagged) InitializerMap((int, double), (int, double))

Coercion table

1 2 3 4 5 6 7 8
1 x x x x x x x x
2 x x
3 x
4 x x x
5 x x
6 x
7 x x
8 x

Struct initialization could be done using 1-6. Array initialization could be done with 1-3.

// Typed map
def make_map(type K, type V) -> Map(K, V)
def make_map(init: InitializerMap([type K], [type V])) -> Map(K, V)

// Untyped table
def make_table(init: Initializer(type K, type V)) -> Table
def make_table(init: InitializerMap(type K, type V)) -> Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant