Basic noob question:
I have data I need to evaluate lazily, the most common way of doing this is by making a thunk
s; the way I'm used to do it is like this:
fun someFunc () =
let
fun myThunk () = 2 + 2
in
(* body *)
end
But every guide on Standard ML tells me that it's done like this:
fun someFunc () =
let
val myThunk = fn () => 2 + 2
in
(* body *)
end
So my questions are: Does it really matter? Isn't the output the same anyway? And what is the difference between making a function, and binding a lambda to a value anyway?
There are no noticeable difference in your case. The fun
keyword is syntactic sugar for val rec
, which makes sure that you can reference the name that you are binding your function to in a recursive manner.
Thus
fun myThunk () = 2 + 2
val rec myThunk = fn () => 2 + 2
val myThunk = fn () => 2 + 2
will all yield the same result.