Definition of New Types

Full Metal Jacket is statically typed. As it lacks variables, types are assigned instead to vertex inputs and outputs (and by implication, the edges which connect them). Types are determined in much the same way as they are in Haskell, i.e. by Hindley-Milner type inference, a mechanism similar to unification in Prolog. However, in Full Metal Jacket, type inference occurs at the earliest possible stage: while the program is being edited, i.e. before running the code, and potentially before compiling it. This means the programmer doesn't need to specify any types, and is still prevented from entering an incorrectly typed program. Type inference is explained in detail in Keyboard? How quaint. Visual Dataflow Implemented in Lisp.

The predefined types in Full Metal Jacket include Int, Real (floating point), Bool (Boolean), Array, Str (string), Sym (symbol), Fun (function), List, AList, Bag, and Channel (for I/O). Types can have subtypes, e.g. a List of Sym.

No additional elements are necessary for type definitions, as new types are defined using directed graphs (in practice, trees), by composing or extending existing types. The body of the type definition used for type inference is gradually built up as it flows downward through the graph, and constructors and deconstructors are automatically generated.

Person

The attributes of Person are name, date of birth and sex. These are not defined as separate getter and setter functions. Instead, the functions unmakePerson and makePerson are defined. A Person's name is the first value returned by unmakePerson, their date of birth is the second value, and their sex is the third value.

Musician

Musician extends Person. A List of Tracks performed by the Musician is added to all the other attributes of Person (e.g. name, date of birth and sex). For example, the Musician Greg Lake played and sang on a performance of 21st Century Schizoid Man and numerous other Tracks.

Musician could be defined in Lisp as

(deftype Musician NIL
  (extend+ Person (List Track)))
Composer

Composition

Track

A Track is a recording of a performance of a Composition. It contains an association list of each Musician and the List of parts performed by them (each represented by a Sym), and the length of the performance. For example, the Composition 21st Century Schizoid Man was performed by the Musicians Robert Fripp on lead guitar, Greg Lake on bass guitar and lead vocals, Ian McDonald on alto saxophone, and Michael Giles on drums, and has length 7.333333 minutes.

Track could be defined in Lisp as

(deftype Track NIL
  (compose+ Composition
            (AList Musician (List Sym))
            Real))

Previous Up Next

© Copyright Donald Fisk 2016