Languages that allow named tuples
c#, return-value, tuples
Solution
In C#, you have anonymous types; these are similar but have their own limitations:
var result = new { Speed = 12.4, Distance = 8, Caption = "car 1" };
However, it is hard to consume these as a caller, unless you use "cast by example" (brittle), reflection, or `dynamic`. Of the three, the last is the most appetising.
dynamic result = GetSomething();
Console.WriteLine(result.Speed);
Console.WriteLine(result.Distance);
In most cases, it would be a better idea just to use a regular class - but this approach does have some practical uses; for example, look at how they are used in ASP.NET MVC to pass around configuration information simply and conveniently (which would otherwise require a dictionary). A bit like how jQuery allows you to pass options as properties on an object.
Problem
I was wondering if there are any languages that allow for named tuples. Ie: an object with multiple variables of different type and configurable name. E.g.: ``` public NamedTuple<double:Speed, int:Distance> CalculateStuff(int arg1, int arg2) var result = CalculateStuffTuple(1,2); Console.WriteLine("Speed is: " + result.Speed.ToString()) Console.WriteLine("Distance is: " + result.Distance.ToString()) ``` I could conceive how a dynamic could support such a feature. The static languages I usually swim in (like c#) can do a Dictionary, but that's not type safe unless all items are of the same type. Or you can use a Tuple type, but that means you have fixed names of the members (Var1, Var2, etc). You could also write a small custom class, but that's the situation I'd like to avoid. I could imagine a macro processing language could script something like that up for you in a static language, but I don't know of such a language. This comes out of my answer from this question about return types.