Overview

The metadef statement declares a new named type, essentially assigning a type expression to a name.

metadef name:type_expression. 

Type Destructuring in metadef

The record and tuple type expressions support the destructuring syntax, allowing you to declare multiple types in one metadef statement.

metadef t_person: (
    $name->t_name: (
        $fname->t_first_name: str,
        $lname->str
    ),
    $address->t_addr: (
        $number->str,
        $street->str,
        $code->int
)).
metadef t_person: (
    $name->t_name: (
        $fname->t_first_name: str,
        $lname->str
    ),
    $address->t_addr: (
        $number->str,
        $street->str,
        $code->int
)).

The example declares these types in one statement:

  • t_first_name as string
  • t_name as a record with two string fields $fname and $lname
  • t_addr as a record with three fields, representing the address
  • t_person as a record of two fields, each of which is also a record, as shown.

Type destructuring is especially convenient in the specification of messaging protocols and database tables. Each row in a table could be a record of records (with, possibly, several levels of records). Declaring all of the involved types in one statement saves a lot of typing.