teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.13k stars 107 forks source link

Reconsider the syntax for maps #643

Closed ccuser44 closed 1 year ago

ccuser44 commented 1 year ago

https://github.com/teal-language/tl/blob/master/docs/tutorial.md#maps

Currently the syntax for maps is

{type : type}

this is a bit ambigious for a few reasons.

First one may look at the first argument as a key name instead of a type. For example in

local function name(arg1: type)

the first arg is a name and the second one is a type. But with tables this is not the case which is very ambigious and odd.

While distinct key name pairs are implemented by records in teal, it would be great if this wasn't as ambigious.

Hence, I propose an alternate syntax for maps which is

{[type]: type}

and deprecate the current syntax (although it should be kept for backwards compatibility purposes).

Having this inside square brackets would make it less ambigious to the reader to understand that the first argument is indeed a type argument not a key name.

hishamhm commented 1 year ago

Thanks for the suggestion, but this is not something I intend to change in the foreseeable future.