PreviousUpNext

5.7.14  Mythryl API Syntax

Signatures are called APIs in Mythryl, for conciseness and improved C intuition.

Pursuing the theme that generics (“functors”) are compile-time functions with package (“structure”) values taking API (“signature”) types, Mythryl APIs take Mixed_Case names just like Mythryl types.

Named APIs are declared using a conventional, compact, Posix-flavored syntax:

    api My_Api {
        Color;                                   # Opaque type declaration.
        Point = TWO_D (Float, Float)             # Transparent type declaration.
              | THREE_D (Float, Float, Float);   
        
        my_function: List(Int) -> Int;           # Function declaration.
    };                                           # All statements end with a semicolon!

To avoid spending an extra reserved word (as does SML with signature and sig) Mythryl uses a simple variant of the above syntax to declare anonymous APIs, merely replacing the API name with the standard underbar wildcard:

    api {
        Color;                                   # Opaque type declaration.
        Point = TWO_D (Float, Float)             # Transparent type declaration.
              | THREE_D (Float, Float, Float);   
        
        my_function: List(Int) -> Int;           # Function declaration.
    };                                           # All statements end with a semicolon!

A Mythryl file declaring an API customarily uses the .api file extension.

Note that despite the use of vertical bar (| ) in the above syntax, it is not a reserved word in Mythryl, and may be freely defined by the application programmer. The default Mythryl library definition is integer inclusive-or, in line with C intuition.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext