1.2. Core Language

1.2.1. Rebinding constructor names with val rec and fun

In SML '90, a data constructor name can be rebound in its scope only by another datatype declaration using that name. In SML '97, data constructor names can also be rebound by recursive function declarations (val rec and fun). See the SML '97 Definition, page 24, rule (26). For instance:
  datatype t = f;
  fun f x = x;
SML/NJ Discrepancy. This change is not yet implemented in SML/NJ. This is bug 1357.

1.2.2. Revised infix operator precedence rules

The way infix operators interact now conforms to the treatment SML/NJ has always implemented (SML '97 Definition, Section 2.6, page 6). If id1 and id2 are left (right) associative infix operators of the same precedence, then an expression of the form
  aexp id1 aexp id2 aexp
(where aexp stands for atomic expressions) associates to the left (right). If id1 and id2 are of the same precedence but different associativities (i.e. one is left associative and the other is right associative), then the SML '97 Definition says that the expression is illegal. SML/NJ is more lenient, and only issues a warning in this case, and breaks the tie by associating to the left.
  - infix 4 <<;
  infix 4 <<
  - infixr 4 >>;
  infixr 4 >>
  - fun (x>>y) = "right";
  val >> = fn : 'a * 'b -> string
  - fun (x<<y) = "left";
  val << = fn : 'a * 'b -> string
  - 1 << 2 >> 3;
  stdIn:21.8-21.10 Warning: mixed left- and right-associative operators of same precedence
  val it = "right" : string
  - 1 >> 2 << 3;
  stdIn:22.8-22.10 Warning: mixed left- and right-associative operators of same precedence
  val it = "left" : string

1.2.3. Forbidden rebindings

To make sure that certain derived form expansions in the semantics (e.g. if expressions translating to case expressions) are robust, SML '97 forbids the rebinding of true, false, nil, ::, and ref. It is also forbidden to bind it as a data constructor or exception constructor. These restrictions are mainly for the sake of the semantics, since most implementations would not be broken by rebinding these identifiers. However, it is a good idea not to redind these key identifers anyway, because doing so is likely to lead to confusion.
SML/NJ Discrepancy: SML/NJ does not currently enforce this restriction. This is bug 1328.

Dave MacQueen
Last modified: Thu Mar 5 14:25:32 EST 1998