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
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.[]()[1, 2, 3][3; int][1, 2.0, 3](int, double, int)[b = 20]struct { b: int }[1, 2, b = 20]Initializer([2; int], struct { b: int })[1, 1.5, b = 20]Initializer((int, double), struct { b: int })[(1) = 20, (2) = 30]InitializerMap([2; int], [2; int])[(1) = 20, (1.5) = 2.5]InitializerMap((int, double), (int, double))Coercion table
Struct initialization could be done using 1-6. Array initialization could be done with 1-3.