Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / UnresolvedBugs.adoc
CommitLineData
7f918cf1
CE
1UnresolvedBugs
2==============
3
4Here are the places where MLton deviates from
5<:DefinitionOfStandardML:The Definition of Standard ML (Revised)> and
6the <:BasisLibrary:Basis Library>. In general, MLton complies with
7the <:DefinitionOfStandardML:Definition> quite closely, typically much
8more closely than other SML compilers (see, e.g., our list of
9<:SMLNJDeviations:SML/NJ's deviations>). In fact, the four deviations
10listed here are the only known deviations, and we have no immediate
11plans to fix them. If you find a deviation not listed here, please
12report a <:Bug:>.
13
14We don't plan to fix these bugs because the first (parsing nested
15cases) has historically never been accepted by any SML compiler, the
16second clearly indicates a problem in the
17<:DefinitionOfStandardML:Definition>, and the remaining are difficult
18to resolve in the context of MLton's implementaton of Standard ML (and
19unlikely to be problematic in practice).
20
21* MLton does not correctly parse case expressions nested within other
22matches. For example, the following fails.
23+
24[source,sml]
25----
26fun f 0 y =
27 case x of
28 1 => 2
29 | _ => 3
30 | f _ y = 4
31----
32+
33To do this in a program, simply parenthesize the case expression.
34+
35Allowing such expressions, although compliant with the Definition,
36would be a mistake, since using parentheses is clearer and no SML
37compiler has ever allowed them. Furthermore, implementing this would
38require serious yacc grammar rewriting followed by postprocessing.
39
40* MLton does not raise the `Bind` exception at run time when
41evaluating `val rec` (and `fun`) declarations that redefine
42identifiers that previously had constructor status. (By default,
43MLton does warn at compile time about `val rec` (and `fun`)
44declarations that redefine identifiers that previously had
45constructors status; see the `valrecConstr` <:MLBasisAnnotations:ML
46Basis annotation>.) For example, the Definition requires the
47following program to type check, but also (bizarelly) requires it to
48raise the `Bind` exception
49+
50[source,sml]
51----
52val rec NONE = fn () => ()
53----
54+
55The Definition's behavior is obviously an error, a mismatch between
56the static semantics (rule 26) and the dynamic semantics (rule 126).
57Given the comments on rule 26 in the Definition, it seems clear that
58the authors meant for `val rec` to allow an identifier's constructor
59status to be overridden both statically and dynamically. Hence, MLton
60and most SML compilers follow rule 26, but do not follow rule 126.
61
62* MLton does not hide the equality aspect of types declared in
63`abstype` declarations. So, MLton accepts programs like the following,
64while the Definition rejects them.
65+
66[source,sml]
67----
68abstype t = T with end
69val _ = fn (t1, t2 : t) => t1 = t2
70
71abstype t = T with val a = T end
72val _ = a = a
73----
74+
75One consequence of this choice is that MLton accepts the following
76program, in accordance with the Definition.
77+
78[source,sml]
79----
80abstype t = T with val eq = op = end
81val _ = fn (t1, t2 : t) => eq (t1, t2)
82----
83+
84Other implementations will typically reject this program, because they
85make an early choice for the type of `eq` to be `''a * ''a -> bool`
86instead of `t * t -> bool`. The choice is understandable, since the
87Definition accepts the following program.
88+
89[source,sml]
90----
91abstype t = T with val eq = op = end
92val _ = eq (1, 2)
93----
94+
95
96* MLton (re-)type checks each functor definition at every
97corresponding functor application (the compilation technique of
98defunctorization). One consequence of this implementation is that
99MLton accepts the following program, while the Definition rejects
100it.
101+
102[source,sml]
103----
104functor F (X: sig type t end) = struct
105 val f = id id
106end
107structure A = F (struct type t = int end)
108structure B = F (struct type t = bool end)
109val _ = A.f 10
110val _ = B.f "dude"
111----
112+
113On the other hand, other implementations will typically reject the
114following program, while MLton and the Definition accept it.
115+
116[source,sml]
117----
118functor F (X: sig type t end) = struct
119 val f = id id
120end
121structure A = F (struct type t = int end)
122structure B = F (struct type t = bool end)
123val _ = A.f 10
124val _ = B.f false
125----
126+
127See <!Cite(DreyerBlume07)> for more details.