-
Notifications
You must be signed in to change notification settings - Fork 856
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
add a new syntactic category: tuples #131
Comments
+1 |
So this is okay? toplevel = [
(1, 2, ["a", "b"]),
(3, 4, [3.64, 21.25]),
(5, 4, [ [ "b" ], [ 1 ], [ 0.0, 0.0, 12.24 ] ])
] |
@renekooi That would be OK given the current spec, since all arrays have type |
This would be awesome together with #28. It would simplify the implementation and API for statically typed languages |
I rather like the notion of tuples. It solves the mixed type array problem and offers a nice way to specify large amounts of homogenous, structured data in an easy way. Almost every language will be able to express tuples in some kind of reasonable way, allowing us to go back to fully homogenous arrays, which I would prefer. @tnm I'd love your take on this. |
I've been thinking this over since the mixed array type discussion started. I'm in favor of tuples. There's significant practical use — the |
Spec'd out in #154. Continue discussion there. |
Regardless of whether issue #28 is accepted, arrays can only contain values of a single data type. While data types can still be mixed at the hash level, it may still be desirable to compactly represent an array of mixed data types. We can do this with tuples. So that while this is illegal
with tuples, it could be represented as
In particular, the type of the above is an
array of int * string * string
if #28 is accepted, or simplyarray
in the current spec.The semantics of a tuple is that its type is the product of the types of its elements. This not only makes it an ordered type, but it fixes the length as well. So that this would not be allowed:
since the first tuple has type
string * string
and the latter has typestring * string * string
.I also propose that tuples with less than 2 elements be forbidden. Any attempt to create them should result in an error.
The actual syntax of a tuple is precisely the same as an array, except with
()
instead of[]
. Tuples may contain arrays and arrays may contain tuples.The text was updated successfully, but these errors were encountered: