question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

labeled tuple types

See original GitHub issue

[@gavinking] Record types are a construct popular in ML-like languages, that are a bit like C-style structs. From our point of view, they are tuples with named elements. An elegant way to add support for record types to Ceylon would be via shared parameters of class aliases, for example:

class Person(shared String first, shared String last, shared Integer age) => [first, last, age];

Then you could write:

Person person = Person("Joe", "Bloggs", 32);
String firstName = person.first;
String lastName = person.last;
Integer age = person.age;

Where Person is just an alias for the type [String,String,Integer], and person.last is just sugar for person[1].

But would this feature be useful to us? I dunno. It might be useful for working with APIs that query relational databases. Apart from that, I can’t think of much use, since for us classes are just much more powerful.

One use we do have for record types is to encode parameter names to function types. But I don’t think the above approach helps us much there. For that problem we would need to be able to write down types like:

Callable<Anything, [String first, String last, Integer age]>

without needing to define an alias first.

[Migrated from ceylon/ceylon-spec#745]

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:34 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
luolongcommented, Apr 5, 2018

AFAICT You don’t name tuples with classes. You simply have classes that have named attributes.

1reaction
xkr47commented, Nov 1, 2016

But at runtime, a [String firstName, String lastName, Integer age] is just a regular [String, String, Integer] tuple. So this whole language feature would have no impact on the backends.

This to me departs from the general Ceylon direction of having more (or even “complete”) metadata available at runtime (than e.g. Java)…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.0
Labeled Tuple Elements. Improving the experience around tuple types and parameter lists is important because it allows us to get strongly typed validation ......
Read more >
Tuple types - C# reference - Microsoft Learn
Tuple types are value types; tuple elements are public fields. That makes tuples mutable value types. The tuples feature requires the System. ...
Read more >
What are “named or labeled tuples” in Typescript?
1 Answer 1 ... This is purely for documentation purposes, it has no semantics. They are just a way of putting names in...
Read more >
Real use cases for named tuples in TypeScript - LogRocket Blog
TypeScript tuples are best used in scenarios in which you know exactly how many types you want to allow in an array.
Read more >
Feature Request: Add labels to tuple elements #28259 - GitHub
Search Terms tuple type elements members labels names naming Suggestion Currently tuple types are defined like so: // length, count type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found