문제

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