Home

F#. "Domain is preserved between queries".

In the forum thread when F# autocompletion hit beta, I suspect I didn't understand what you meant by "Domain is preserved between queries".

I have the following (F# program query type):

printfn "Hello"

printfn "World"

let add a b = a + b

add 1 2 |> printfn "%d"



After running the whole program, am I not supposed to be able to mark and run only the last line because the session will remember that "add" is defined on a previous pass?

Comments

  • When you highlight a selection and execute it, LINQPad (re)compiles the selected text to a new assembly, so the 'add' function that your code refers to is different to the one you had before.

    You won't normally see the effect of preserving the domain (aside of improving performance), except in cases such as the following (in C#), when you re-run the query without making any changes:
    
    static int x = 0;
    
    void Main()
    {
    	(x++).Dump();
    } 
    
    Another case when the cached domain is relevant is when calling static members of a type defined somewhere else (e.g., in My Extensions, or in a library, or in LINQPad itself). LINQPad's Util.Cache method makes use of this:

    http://share.linqpad.net/g2w9se.linq


  • Right. As I suspected, I misunderstood the response in this thread:
    https://forum.linqpad.net/discussion/comment/2060#Comment_2060

    In F#, it's pretty common to have various definitions laying around and composing ad hoc on a powerful toolbox of functions. As I understand it now, I will have to run the whole query top to bottom for every REPL style consumption of the functions.

    In the other thread, you asked me if the REPL workflow would require a different editor. I think just selecting a line and hitting F5 would be sufficient, as long as the definitions from earlier F5 executions were available (until you hit ctrl-shift-F5)

    What would that feature request be called? "Preserving the domain" clearly wasn't it. Is it realistic?
Sign In or Register to comment.