2 ms·
Are you effectively interpreting it, or are you compiling it to something else? I'm really curious how you do this in a performant way.
by 6gvONxR4sf7o 7y ago
Are you effectively interpreting it, or are you compiling it to something else? I'm really curious how you do this in a performant way.
- Smaug123 7y agoWe have places where we ultimately emit IL (the bytecode of .NET). However, usually we just emit F#, restricted to certain constructs which are allocation-free and so forth. We aren't producing F# in the sense that we have to invoke the F# compiler ourselves, though. In the calculator example, given the description `Add (Negate (Const 5)) (Const 3)`, we might ultimately end up having assembled an F# function in memory like `fun () -> -5 + 3`; when this function is invoked, the value `-2` will be calculated. Ultimately we usually put together the functions in the usual way you make a function: by composition of smaller functions. The very simplest expressions like `Const 5` have a simple template like `fun () -> 5` which we can just directly produce; more complex expressions have to be interpreted recursively into F# function objects. I agree it's a bit hard to explain unless you're trying to solve a less trivial problem :(