1 people like it.

[HELP!] How to separately compile a function in F# at RUN-TIME ?

Hello everyone, I'm a student who's programed with F# for 8 months. With F#, I managed to write an interpreter for my own language. By using higher order functions and abstract syntax tree, my interpreter can turn the whole program written by programmers (in the form of a string[]) into a single unit->unit function which actually runs (exactly) what programmers wrote in the string[]. The thing is I'd like to know if there are ways to compile/ convert a function into a .exe file. If someone's willing to help me, feel free to leave a comment by editing this snipet. /// Please note that I'm asking how to compile a function (can be unit or unit->unit) at RUN-TIME. Thank you in advance. /// Oh, by the way, I left the link to the source code of my interpreter. This may be useful for you to help me. /// Please, just don't laught at my interpreter and the way I wrote it.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
open System

let CompileThis =
    printfn "This is the function needing compling."
    printfn "Is there anyway that I can create a .exe file running the function \"CompileThis\" only ?"

let DontCompileThis =
    printf "The .exe file created along with the program's .exe must not contain this function"

// Other things ...

// When the program run (run-time), another .exe file will be created, which runs "CompileThis".

// Link to the source code: https://repl.it/@NoFriend/EGGv04Beta#main.fs
namespace System
val CompileThis : unit
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
val DontCompileThis : unit
val printf : format:Printf.TextWriterFormat<'T> -> 'T

More information

Link:http://fssnip.net/7Yq
Posted:3 years ago
Author:A Person Trying To Sharpen His Programming with F# Everyday
Tags: compiler , interpreter , run time , newbie