Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading F# module in FSI

Tags:

f#

I have a fsx file that I use for interactive development of my project. It preloads all the dlls plus I want to mock a couple of functions that should behave differently in FSI world.

In fsx I have this code:

// #r needed dlls
open FSharp.Charting

module InteractiveUtil =
    let plotMe (c : ChartTypes.GenericChart) = c.ShowChart() |> ignore
    let logMe (c : string) = c |> printfn "%s"

Now in .fs files I want to play with I have this:

#if INTERACTIVE
#load "LiveInvestigationPreload.fsx"
open InteractiveUtil
#endif

But when I try to execute snippet above I get

error FS0039: The namespace or module 'InteractiveUtil' is not defined

I also noticed that definition of InteractiveUtil module looks like this:

namespace FSI_0009
  module InteractiveUtil = begin
    val plotMe : c:FSharp.Charting.ChartTypes.GenericChart -> unit
    val logMe : c:string -> unit
  end

So FSI_0009 is something fsi created for me.

Any idea how to get around this?

like image 457
Klark Avatar asked Nov 10 '22 22:11

Klark


1 Answers

Ok, got it. When I put top level module in the beginning of fsx it worked.

module InteractiveUtil

#time
#r ...
open FSharp.Charting

let plotMe (c : ChartTypes.GenericChart) = c.ShowChart() |> ignore
let logMe (c : string) = c |> printfn "%s"

I would have deleted the question but since I already got one vote up it seems like someone else is interested in solution.

like image 128
Klark Avatar answered Jan 04 '23 01:01

Klark