PreviousUpNext

5.7.13  Mythryl Type Syntax

Mythryl requires all type names to be in Mixed_Case and all constructors to be in UPPER_CASE (with the sole exception of the list constructor ’!’). Combined with the requirement that all statements end with a semicolon, this allows concise type declarations.

Mythryl declares tuples using parentheses-and-commas syntax parallel to normal tuple construction syntax. This loses the tie to mathematical set product notation, but carries better C intuition and is more consistent with the way records types are declared in both SML and Mythryl:

    My_Tuple = (Int, Float, String);

A simple sumtype declaration is now simply

    Color = RED | GREEN | BLUE;

Declaring the same type opaque in an API (signature) is even more concise:

    Color;

Mythryl does not use the SML of particle in sumtype declarations. (Mythryl returns of to the general identifier pool, reducing the reserved word count by one.)

    Point = TWO_D (Float, Float) | THREE_D (Float, Float, Float);

Mythryl uses prefix type functions (“type constructors”), in contrast to SML’s postfix type syntax. A list of strings type is now:

    List_Of_Strings = List(String);

Record and function type declarations are otherwise unchanged:

    My_Record_Type = { name: String, age: Int };
    My_Arrow_Type  = List(Int) -> Int;

Mythryl type variables are typically single uppercase letters, canonically X Y Z:

    Typeagnostic_Tuple(X, Y) = (List(X), Y, X -> Y);

Relative to SML type variable syntax 'a, the Mythryl syntax carries better intuition to C programmers, and incidentally frees up leading apostrophe to implement normal C-style character constant syntax.

When more semantic content is needed, longer type variable names incorporating a single leading capital may be used:

    Typeagnostic_Tuple(A_boojum, A_snark) = (List(A_boojum), A_snark, A_boojum -> A_snark);

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext