I noticed I can declare tuples in nimrod without giving names for each filed. For example:

type T1 = tuple[string, age: int]
type T2 = tuple[char, string, age: int]

But this doesn't apply for the last filed

type T3 = tuple[string, int] # compilation error

Why is that? Is this intended? Why should the last field always be named?

有帮助吗?

解决方案

The compiler actually interprets T1 as a tuple with fields named string and age both of type int and T2 as a tuple with fields named char, string, and age of type int. In short, the standalone "types" in the comma-separated list are interpreted as field names.

This is likely a compiler bug (as you can't use the field names for constructors) in that it doesn't validate the field names. But it's not that you have to provide a type for the last element only: the type will apply to all the elements in the comma-separated list preceding the colon.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top