| 1 |
= ShowBasis |
| 2 |
|
| 3 |
MLton has a flag, `-show-basis <file>`, that causes MLton to pretty |
| 4 |
print to _file_ the basis defined by the input program. For example, |
| 5 |
if `foo.sml` contains |
| 6 |
[source,sml] |
| 7 |
---- |
| 8 |
fun f x = x + 1 |
| 9 |
---- |
| 10 |
then `mlton -show-basis foo.basis foo.sml` will create `foo.basis` |
| 11 |
with the following contents. |
| 12 |
---- |
| 13 |
val f: int -> int |
| 14 |
---- |
| 15 |
|
| 16 |
If you only want to see the basis and do not wish to compile the |
| 17 |
program, you can call MLton with `-stop tc`. |
| 18 |
|
| 19 |
== Displaying signatures |
| 20 |
|
| 21 |
When displaying signatures, MLton prefixes types defined in the |
| 22 |
signature them with `_sig.` to distinguish them from types defined in the |
| 23 |
environment. For example, |
| 24 |
[source,sml] |
| 25 |
---- |
| 26 |
signature SIG = |
| 27 |
sig |
| 28 |
type t |
| 29 |
val x: t * int -> unit |
| 30 |
end |
| 31 |
---- |
| 32 |
is displayed as |
| 33 |
---- |
| 34 |
signature SIG = |
| 35 |
sig |
| 36 |
type t |
| 37 |
val x: _sig.t * int -> unit |
| 38 |
end |
| 39 |
---- |
| 40 |
|
| 41 |
Notice that `int` occurs without the `_sig.` prefix. |
| 42 |
|
| 43 |
MLton also uses a canonical name for each type in the signature, and |
| 44 |
that name is used everywhere for that type, no matter what the input |
| 45 |
signature looked like. For example: |
| 46 |
[source,sml] |
| 47 |
---- |
| 48 |
signature SIG = |
| 49 |
sig |
| 50 |
type t |
| 51 |
type u = t |
| 52 |
val x: t |
| 53 |
val y: u |
| 54 |
end |
| 55 |
---- |
| 56 |
is displayed as |
| 57 |
---- |
| 58 |
signature SIG = |
| 59 |
sig |
| 60 |
type t |
| 61 |
type u = _sig.t |
| 62 |
val x: _sig.t |
| 63 |
val y: _sig.t |
| 64 |
end |
| 65 |
---- |
| 66 |
|
| 67 |
Canonical names are always relative to the "top" of the signature, |
| 68 |
even when used in nested substructures. For example: |
| 69 |
[source,sml] |
| 70 |
---- |
| 71 |
signature S = |
| 72 |
sig |
| 73 |
type t |
| 74 |
val w: t |
| 75 |
structure U: |
| 76 |
sig |
| 77 |
type u |
| 78 |
val x: t |
| 79 |
val y: u |
| 80 |
end |
| 81 |
val z: U.u |
| 82 |
end |
| 83 |
---- |
| 84 |
is displayed as |
| 85 |
---- |
| 86 |
signature S = |
| 87 |
sig |
| 88 |
type t |
| 89 |
val w: _sig.t |
| 90 |
val z: _sig.U.u |
| 91 |
structure U: |
| 92 |
sig |
| 93 |
type u |
| 94 |
val x: _sig.t |
| 95 |
val y: _sig.U.u |
| 96 |
end |
| 97 |
end |
| 98 |
---- |
| 99 |
|
| 100 |
== Displaying structures |
| 101 |
|
| 102 |
When displaying structures, MLton uses signature constraints wherever |
| 103 |
possible, combined with `where type` clauses to specify the meanings |
| 104 |
of the types defined within the signature. For example: |
| 105 |
[source,sml] |
| 106 |
---- |
| 107 |
signature SIG = |
| 108 |
sig |
| 109 |
type t |
| 110 |
val x: t |
| 111 |
end |
| 112 |
structure S: SIG = |
| 113 |
struct |
| 114 |
type t = int |
| 115 |
val x = 13 |
| 116 |
end |
| 117 |
structure S2:> SIG = S |
| 118 |
---- |
| 119 |
is displayed as |
| 120 |
---- |
| 121 |
signature SIG = |
| 122 |
sig |
| 123 |
type t |
| 124 |
val x: _sig.t |
| 125 |
end |
| 126 |
structure S: SIG |
| 127 |
where type t = int |
| 128 |
structure S2: SIG |
| 129 |
where type t = S2.t |
| 130 |
---- |