Open thosakwe opened 6 years ago
Maps could just be part of the stdlib:
final map = Map<Int, Int>();
map[2] = 34;
An object literal can have three kinds of members:
KeyValuePair
SimpleIdentifier
(for assigning a key to a variable of the same name)ObjectSpread
Respectively:
{ foo: bar, baz, ...quux }
We could still keep Map literals while still introducing Object initialization. We can decipher that it is object initialization from the context.
I’m not 100% sure that we could decipher the type from the context. In cases where return types are not present, it would be ambiguous whether an object is an object or a map.
I think we’ll be able to figure something out.
Do any languages other than Dart have Map literals?
My personal opinion is that the only types that should have literal representations are primitives, including arrays, and then object types so the language can be expressive, but also very clear.
An object literal makes Bonobo very expressive, and allows users to return typed data without having to instantiate a class.
At least for now, I'm hoping we can get away entirely without having to add classes. Especially when compiling to C or LLVM, that adds quite a bit of complication that frankly can and should be avoided.
But, we'll see.
Anyways, all keys should be simple identifiers. I see no advantage of having maps built in to the syntax itself. Those can be part of the standard library.
Note that though this is just an object of a user-defined, anonymous type, the analyzer can easily verify that it matches the type aliased to
MyRecord
.