Open WhiteBlackGoose opened 2 years ago
If we're going to define explicit types using colon then using colons for separating tuple members is going to be confusing.
Consider this:
val greeting : String = "hello there"
val greetings : String[] = "hello there" : "general kenobi"
//or even worse for custom classes
val myCars : Vehicles = GMC() : AUDI()
//or enums
val results : Result = Finished : Started : Working
It's very easy to miss the equal sign and more importantly, I think naturally colon (:
) as punctuation is used for describing something, iterating a list, quoting someone in other words it's always about describing equal of something in other ways not as a separator, for example:
See that!? I just used colon.
here's a list of colors: red, green, blue, etc.
GNU: GNU Not Unix
Even the JSON example that you provided is using a colon for defining the relationship between key and value not for showing the relationship between different members of a group.
Yeah, I agree. We're also considering #28 to solve this.
here's a list of colors: red, green, blue, etc.
But note, that what you said is actually a tuple in one of the interpretations. ("colors", [red, green, blue])
. With colon it is much more readable, I think, than listOfColors(red, green, blue)
in the mentioned cases.
While we all can probably agree that tuples will be created as
(a, b)
or(a, b, c)
etc., I suggest (as a crazy idea) operator:
for creating tuples.Definition
Type
In fact it's neither ValueTuple nor Tuple. It's ColonTuple. It's implicitly convertable from/to ValueTuple and Tuple though. And it's immutable.
The reason I want it to be a different type is because in many cases it makes sense to use what was created by colon, but not by regular tuple (for example sequences and slicing, see below).
Syntax
E. g.
It's low priority, so e. g.
1 * 2 : 3
would be(1 * 2, 3)
and1 : 3.Method()
would be(1, 3.Method())
.But it's higher priority than comman, so
Method(1 : 3, 5)
would beMethod((1, 3), 5)
What problems can be solved
DSL
This definitely helps with writing GUI, css, json, and probably many more. It'd create great opportunities for whatever looks like range or map. E. g.
Similarly,
Dictionaries
They can be created from a sequence of tuples of TKey and TValue, so
As sequences
Numeric colon types can be interpreted as sequences!
As ranges for slicing
We can create overloads for BCL types by adding indexers for ColonTuple:
(what those numbers mean in particular to indexers is yet to decide)