简体   繁体   中英

F# Create function at runtime

I know it is related to this SO question and this one , but I want to know, if (and how) it is possible to create new F# functions at runtime.

By this I mean something like using the REPL without showing it. Is there any other option than CodeDOM and Reflection or Quotations?

If it is not possible in F#, is it possible in any other .Net Language?

Sure you can, that's what the DLR (Dynamic Language Runtime) is for. It's used by IronPython, IronRuby, and other dynamic languages which work exactly as you describe. The DLR is just a library, so you can use it from within F# if you want.

Another option is to implement similar functionality using F#'s higher-order functions -- this would be very flexible, but ultimately somewhat slower because the .NET CLR won't be able to do much (if anything) in the way of optimization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM