-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest16.txt
46 lines (35 loc) · 1.33 KB
/
test16.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
*************** Source File ****************
(*
This program type checks correctly as it stands, but it should
not. This is an example of a program that demonstrates that the
implementation of type checking for MLComp is not sound.
This program and why it should not type check correctly is
discussed at
http://www.smlnj.org/doc/Conversion/types.html
where it explains why this should not pass the type checker
and how that is handled correctly in SML/NJ.
*)
let val r = ref(fn x => x)
in
r := (fn x => x+1);
!r true
end
******************* AST ********************
letdec(
bindval(idpat('r'),apply(id('ref'), func('anon@0',[
match(idpat('x') ,id('x') )
]))),
[
apply(id(':='),tuplecon([id('r') , func('anon@1',[
match(idpat('x') ,apply(id('+'),tuplecon([id('x') ,int('1')])) )
])])) ,apply(apply(id('!'),id('r')),bool('true'))
])
.
************* Type Checking ****************
Typechecking is commencing...
Here is the AST
letdec(bindval(idpat(r),apply(id(ref),func(anon@0,[match(idpat(x),id(x))]))),[apply(id(:=),tuplecon([id(r),func(anon@1,[match(idpat(x),apply(id(+),tuplecon([id(x),int(1)])))])])),apply(apply(id(!),id(r)),bool(true))])
val r : ('a -> 'a) ref
val it : bool
The program passed the typechecker.
********* Target Program Execution *********