Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#load fails to load shared .fsx

Why doesn't #load work

I've tried it in the same folder and in a relative folder as below

What am I missing?

run.fsx is

#load "../shared/shared.fsx"
let key = "MyKey"

let Run(message: string, log: TraceWriter, result: byref<string>) =
    result <- doItAll message key

    log.Info(sprintf "F# results: %s" result)

shared.fsx is

let doItAll message key = key + " has handled " + message

error is

run.fsx(x,y): error FS39: The value or constructor 'doItAll' is not defined
like image 249
David Lapeš Avatar asked Mar 27 '17 11:03

David Lapeš


1 Answers

If you do not specify a namespace or a module name explicitly in shared.fsx, then the F# compiler will put the code in the file in an implicitly named module Shared. You should be able to fix the error by adding open Shared:

#load "../shared/shared.fsx"
open Shared

let key = "MyKey"

let Run(message: string, log: TraceWriter, result: byref<string>) =
    result <- doItAll message key    
    log.Info(sprintf "F# results: %s" result)

If you want to control the naming yourself, you can also add module declaration in shared.fsx and give an explicit name yourself:

module SharedStuff

let doItAll message key = key + " has handled " + message
like image 199
Tomas Petricek Avatar answered Nov 08 '22 16:11

Tomas Petricek