## MLton 20241230

# ShowBasis

MLton has a flag, `-show-basis <file>`, that causes MLton to pretty print to file the basis defined by the input program. For example, if `foo.sml` contains

    fun f x = x + 1

then `mlton -show-basis foo.basis foo.sml` will create `foo.basis` with the following contents.

    val f: int -> int

If you only want to see the basis and do not wish to compile the program, you can call MLton with `-stop tc`.

## Displaying signatures

When displaying signatures, MLton prefixes types defined in the signature them with `_sig.` to distinguish them from types defined in the environment. For example,

    signature SIG =
       sig
          type t
          val x: t * int -> unit
       end

is displayed as

    signature SIG =
       sig
          type t
          val x: _sig.t * int -> unit
       end

Notice that `int` occurs without the `_sig.` prefix.

MLton also uses a canonical name for each type in the signature, and that name is used everywhere for that type, no matter what the input signature looked like. For example:

    signature SIG =
       sig
          type t
          type u = t
          val x: t
          val y: u
       end

is displayed as

    signature SIG =
       sig
          type t
          type u = _sig.t
          val x: _sig.t
          val y: _sig.t
       end

Canonical names are always relative to the "top" of the signature, even when used in nested substructures. For example:

    signature S =
       sig
          type t
          val w: t
          structure U:
             sig
                type u
                val x: t
                val y: u
             end
          val z: U.u
       end

is displayed as

    signature S =
       sig
          type t
          val w: _sig.t
          val z: _sig.U.u
          structure U:
             sig
                type u
                val x: _sig.t
                val y: _sig.U.u
             end
       end

## Displaying structures

When displaying structures, MLton uses signature constraints wherever possible, combined with `where type` clauses to specify the meanings of the types defined within the signature. For example:

    signature SIG =
       sig
          type t
          val x: t
       end
    structure S: SIG =
       struct
          type t = int
          val x = 13
       end
    structure S2:> SIG = S

is displayed as

    signature SIG =
       sig
          type t
          val x: _sig.t
       end
    structure S: SIG
                 where type t = int
    structure S2: SIG
                  where type t = S2.t