A content question (not a homework question) from a Coursera course on programming languages (taught at U of Washington) - I'm getting no response on the Coursera forum....
Abridged code (variable 'cbs' is a list reference that is already defined before this):
(* function to add a callback to the callback list *)
onKeyEvent f = cbs := f :: (!cbs)
(* then, later, in the client code.... *)
val _ = onKeyEvent (fn _ => timesPressed := (!timesPressed) + 1)
Professor writes, "The 'val _ = e' idiom is common for executing an expression just for its side-effect, in this case registering a callback.
What I do not understand is why not just call the function above directly, as in:
onKeyEvent(fn _ => timesPressed := (!timesPressed) + 1)
Why call it by binding it to "_" ? Professor says this is a style thing, but it seems completely unnecessary and complicating.
Thanks for any feedback on this.