is there a eval function in ML?
3 Answers
ML is really just a dialect, but no ML implementation that I've used (OCaml, F#) has eval as far as I know. This makes sense as ML uses strict typing (the types are known at compile time). Eval would break that guarantee.
However I did find an implementation of eval in OCaml that apparently uses code from the toplevel:

- 16,883
- 1
- 35
- 44
-
I believe the term you want is "static typing" – user102008 Jan 25 '12 at 05:06
Yes, at least SML/NJ and Poly/ML can do this: code is compiled at run-time and added to the environment.
For Poly/ML there is a worked example here: ML REPL
Poly/ML can do more things like that, e.g. managing the ML environment under program control. It also supports source-level debugging, with arbitrary evaluation at breakpoints.
It is possible to have some sort of eval in F#, but the code to be evaluated has to be quoted.
#r"FSharp.PowerPack.dll"
#r"FSharp.PowerPack.Linq.dll"
(* load the PowerPack *)
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.QuotationEvaluation
let x = <@@ 8*11 @@>
x.EvalUntyped() // = 88
More about code quotations: http://msdn.microsoft.com/en-us/library/dd233212.aspx

- 637
- 4
- 12