Problem Set 5A Examples

Level 1

Analyze callgraph >> let fun ford(x:int):int = x-20 fun arthur(y:int):int = y*10 fun marvin(z:int):int = arthur(z)+2 in marvin(24) end
callgraph analyzed at level 1:
Dead functions: ford
Rewritten code:
let fun arthur(y) = (y*10) fun marvin(z) = (arthur(z)+2) in marvin(24) end

Analyze callgraph >> let fun f(x:int):int = if true then 42 else g(x) fun g(x:int):int = if x > 0 then h(x) else g(x) fun h(x:int):int = if x < 0 then g(x) else f(x) in f(42) end
callgraph analyzed at level 1:
Dead functions: None
Rewritten code:
let fun f(x) = if true then 42 else g(x) fun g(x) = if (x>0) then h(x) else g(x) fun h(x) = if (x<0) then g(x) else f(x) in f(42) end

Analyze callgraph >> let fun ford(x:int):int = x-20 fun arthur(y:int):int = y*10 fun marvin(z:int):int = arthur(z)+2 in 42 end
callgraph analyzed at level 1:
Dead functions: ford,arthur,marvin
Rewritten code:
let in 42 end

Analyze callgraph >> let fun f(x:int):int=f(x)+1 fun g(x:int):int=x+2 in g(3) end;
callgraph analyzed at level 1:
Dead functions: f
Rewritten code:
let fun g(x) = (x+2) in g(3) end

Analyze callgraph >> let fun f(x):int=x+1 fun g(x):int=(#2(f(x),f(x-1))) in g(3) end;
callgraph analyzed at level 1:
Dead functions: None
Rewritten code:
let fun f(x) = (x+1) fun g(x) = #2(f(x),f((x-1))) in g(3) end

Analyze callgraph >> let fun f(x):int list=[1,2,3] fun g(x):int list= [2,3,f(x)] in g(3) end;
callgraph analyzed at level 1:
Dead functions: None
Rewritten code:
let fun f(x) = [1,2,3] fun g(x) = [2,3,f(x)] in g(3) end

Analyze callgraph >> let fun f(x):int*int*int=(1,2,3) fun g(x):int*int*int=(2,3,f(x)) in g(3) end;
callgraph analyzed at level 1:
Dead functions: None
Rewritten code:
let fun f(x) = (1,2,3) fun g(x) = (2,3,f(x)) in g(3) end

 


Level 2

Analyze callgraph >> let fun ford(x:int):int = x-20 fun arthur(y:int):int = marvin(y*10) fun marvin(z:int):int = arthur(z)+2 in marvin(24) end
callgraph analyzed at level 2:
Recursive functions: arthur,marvin

Analyze callgraph >> let fun ford(x:int):int = marvin(x-20) fun arthur(y:int):int = ford(y*10) fun marvin(z:int):int = arthur(z)+2 in 42 end
callgraph analyzed at level 2:
Recursive functions: ford,arthur,marvin


Level 3

Analyze callgraph >> let fun ign2(x:unit,y:int):int = y fun inc(x:int ref):int = ign2(x:= !x+1,arthur(!x)) fun arthur(z:int):int = inc(z) val ford = ref 41 in inc(ford) end
callgraph analyzed at level 3:
Imperative functions: inc,arthur

Analyze callgraph >> let fun ign2(x:unit,y:int):int = y fun inc(x:int ref):int = ign2(x:= !x+1,!x) fun arthur(z:int):int = inc(z) val ford = ref 41 in inc(ford) end
callgraph analyzed at level 3:
Imperative functions: arthur,inc