How to load external F# script file and use it in

2019-01-24 00:24发布

I would like to load one or more .fsx files into the F# interactive and have all the functions defined in the .fsx files in scope so that I can directly use the functions in the console.

The #load directive executes the .fsx file specified, but then I am no longer able to use those functions in the .fsx file. Any workaround for this? Thanks.

2条回答
做自己的国王
2楼-- · 2019-01-24 01:07

If you don't declare a module in fsx file, it implicitly creates a module the same name as file name.

Therefore, you can always refer to another fsx file using fully qualified names or opening respective modules before use. For example, in Script2.fsx you can do:

#load "Script1.fsx"

open Script1

// Use functions in Script1.fsx
// ...
查看更多
叛逆
3楼-- · 2019-01-24 01:12

I suspect that the script you are loading is not in a module which may be causing your problem. Just add

module Script1

in the first script and then you can do

#load "Script1.fsx"
open Script1

and your functions will be accessible

查看更多
登录 后发表回答