Experimentation Stage

Tuples

Tuples are similar to sequences, but each index has its own type. Tuples are fundamental types in Lense. Structurally a Tuple is a node in a linked-list kind of structure. But a Tuple is not a Sequence, eventhought it is an Iterable<Any> The literal syntax is similar to `Sequence`s, but with parentesis instead of brakets.

let tuple : (Natural , String , Boolean) = ( 1 , "a" , true );

This creates a tuple of 3 elements where the first is a Natural, the second a String and the third a Boolean. You can also observe that the type of the tupe is a tuple of the types.

The tuple is a fundamental type with a lot of syntax sugar in Lense. That code may be compiler as:

let tuple : Tuple<Natural , Tuple<String, Tuple< Boolean, Nothing >>> = Tuple.of( 1 , Tuple.of("a" , Tuple.of(true)));

You can write it like that, if you really want to, but Lense assumes you don’t wish to. Lense supports literals for tuple instances and types.

Accessing elements

To access an element in the tuple you use it’s index property:

let tuple  = ( 1 , "a", true);

let number = tuple[0];
let name = tuple[1];
let predicate = tuple[2];

Tuples do not really have indexers like sequencs do, but the compiler can translate that code to:

let tuple  = Tuple.of( 1 , Tuple.of("a" , Tuple.of(true)));

let number = tuple.head;
let name = tuple.tail.head;
let predicate = tuple.tail.tail.head;

Tuple of 1

These lines are equivalent:

let tuple : (Natural)  = ( 1 );
let value : Natural  = 1;

Lense understans that a single value and a 1-tuple, are the same thing so the compiler enables the translation dynamicaly.

Void

The Void type is a special case of a tuple. The 0-tuple. A 0-tuple can only have one element. This element is designated by the () literal.

public class Void extends Tuple<Nothing, Nothing> {}