# Standard ML of New Jersey Extensions

The Fellowship of SML/NJ
version 110.85, December 21, 2018

The Standard ML of New Jersey (SML/NJ) system implements a number of extensions to the language as defined by the Definition.

## Module language extensions

### Higher-order functors

### Structure constraints for signatures

    structure ASTRUCT :> ASIG where B = BSTRUCT

## Core language extensions

### Vector expressions and patterns

SML/NJ extends the expression and pattern matching syntax to include support for vectors of some known size. The syntax is similar to that of list patterns, except that the opening bracket has a preceeding `#` character. For example,

      fun scaleV (s : real, #[x, y, z]) = #[s*x, s*y, s*z]

This extension is always enabled in SML/NJ.

### Or patterns

TO BE WRITTEN

### Lazy datatypes and functions

SML/NJ provides support for lazy data structures with an extension to the datatype and function declaration forms (`val rec`). There are a number of ways to enable this feature, depending on the ??

- From the command-line, you can use the `-Clazysml=true` flag when launching SML/NJ.

- From the REPL, you can enable the feature using the SML command:

        Control.lazysml := true;

- In a CM, file you can specify that a source file uses the lazy keyword in a number of different ways. The following three lines all have the effect of enabling the `lazy` keyword during compilation of the file.

      foo.sml : lazysml
      foo.sml : sml (lazy)
      foo.sml (with:parser.lazy-keyword=true)

TO BE WRITTEN

      datatype lazy 'a stream = Nil | Cons of 'a * 'a stream;

      fun lazy map f Nil =  Nil
             | map f (Cons(x,xs))  =  Cons(f x, map f xs);

### Quotation/antiquotation

TO BE WRITTEN

## Successor ML extensions

Successor ML (sML) is an effort to continue to grow and improve the SML language. Andreas Rossberg has defined and implemented an some of the proposed features in a version of HaMLet. We are beginning to implement these features in SML/NJ in coordination with the MLton implementation.

### Lexical extensions

As of version 110.79, SML/NJ supports the sML lexical extensions. These can be enabled using the command-line option `-Cparser.succ-ml=true` or the assignment

      Control.succML := true;

in the REPL.

#### Numeric literals (SML/NJ 110.79)

The syntax of numeric literals is extended in two ways. First, the underscore character ("`_`") is now allowed as a separator between digits in a numeric literal. For example,

      123_456
      0wxff_ff_ff_f3
      123_456.1

are valid numeric literals under this extension, but the following are not:

      123._456		(* underscore not proceeded by digit *)
      0wx_ff_ff_ff_f3	(* leading underscore *)

The second extension is binary literals for both integers and words. Similar to hexidecimal literals, the syntax uses a leading "`0b`" to signal a binary literal. Examples include

      0b0101_1110	(* the same value as 0x56 or 86 *)
      0wb1101	(* the same value as 0wD or 13 *)

#### Line comments (SML/NJ 110.79)

This extension adds line comments (i.e., comments that are terminated by the end of the line) to SML. These comments are denoted using the character sequence "`(*)`". Line comments properly nest into conventional block comments. For example, the following block comment is well formed:

      (*
      fun f x = x (*) my identity function *)
      *)