1
votes

I have a finit.fsx file to be load at fsi.exe startup like:

#r xxxx
type xx = xxx
module Util = 
   let cd path = xxxx
   ...

After start fsi.exe, it is loaded as

namespace FSI_0002
  module Util = begin
    val cd : string -> unit
  ...
  end

The problem is how can I use module util? I cannot open Util or use cd directly. To further puzzle me, if I put a namespace at the top line like namespace Test, In fsi.exe, it is loaded as

namespace FSI_0002.Test
  val cd : string -> unit
  ...

Where is the Module Util? I then have to open Test;; then Util.cd.

Is there a way to define module in the F# startup script and auto open the module? thanks.

2

2 Answers

5
votes

I believe you can explicitly specify that all code in the .fsx file is in some module (say, Main) and add the AutoOpen attribute to the module:

[<AutoOpen>]
module Main

let foo = 10

When you then #load the file, the foo value should be visible at the top-level.

2
votes
[<AutoOpen>]
module Util = 
   let cd path = ...