MPS 2024.1 Help

Tuples

Tuples give you a way to group related data of different types into small collection-like data structures. In MPS, tuples are available within the jetbrains.mps.baseLanguage.tuples language.

Indexed tuples

Indexed tuple is a structure, which can contain several elements of arbitrary types and elements of which can be accessed by an index. The MPS implementation represents a tuple instance by a Java object. The usual meaning of '=' and '==' operations on Java objects within MPS remains unchanged.

[int, string] pair = [1, "a"]; int first = pair[0]; string second = pair[1];

Named tuples

Named tuples are similar to indexed tuples, with the difference that elements are accessed by name instead of by index. To use named tuples in the model you first need to explicitly define them in your model (new ->jetbrains.mps.baseLanguage.tuples/tuple).

(first, second)<string, int> pair = (first = "abcd", second = 1);

Declaration of Pair:

public tuple Pair<S, T> { S first; T second; }

Named tuple declaration

A root node of concept NamedTupleDeclaration contains a single declaration.

[public|protected|private] tuple tupleName<TypeVar, ...> { elementType elementName; }

declaration part

allowed contents

tupleName

any valid identifier

elementType

either a primitive type or any type that reduces to Java classifier

elementName

any valid identifier

Last modified: 11 February 2024