If I have a program say:
fun foo x =
let
fun bar y = y * y
in
x + (bar x)
end
foo 123;
When I run this program in SML/NJ without compiling, will it have to process the declaration of bar
each
time foo
is called? As it would in an interpreted language.
Will it run slower than
fun bar y = y * y
fun foo x = x + (bar x)
foo 123;
Since value bindings get updated when each time you call a function this question has been brought to my mind.
Or will SML solve this in some neat way under the hood?
SML/NJ in interactive mode still compiles your functions to native code. By the time you've declared foo
, your intermediate variables have probably been optimised away. i.e. Chances are it will compile down to the same as something like val foo = fn x => x + (x * x)
, and without the overhead of a second function, it should be faster if anything.