Tuples Support in the MPS Base Language

Many functional and dynamic languages have “tuples” in their syntax. Tuple is a sequence of a fixed length. For example, pair, triple and quadruple are tuples. They are very useful when you have algorithms operating on entities which have two, three or more parts and you don’t want to create devoted classes for them, or if you want to return multiple instances from a method.

Let’s take a closer look at how tuples are implemented in MPS.

We have a tuple type. Here is a pair of String and int:


We have a special syntax for tuple construction: we added a new type of literal to the base language:

Each element of a tuple has a name by which it can be accessed:


Tuples are immutable, so you can only create new tuples but can’t change the existing ones. If two tuples contain same element types but different names they are compatible. I.e. you can write:

It took us only about half a day to implement such a cool features in MPS, so it isn’t really hard to do. This feature is going to be available in MPS Beta 2.

MPS Beta 2 should be available next week. Check back at MPS web site or at this blog for the announcement.

Posted by Konstantin Solomatov, Lead MPS developer

This entry was posted in Feature and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">