# How to open modules in F# Interactive?

**URL:** <https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822>\
**Category:** Uncategorized\
**Created:** [May 23, 2019, 9:13pm UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822 "2019-05-23T21:13:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![egp](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@egp](https://forums.fsharp.org/u/egp)\
**Post date:** [May 23, 2019, 9:13pm UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/1 "2019-05-23T21:13:19Z")

</div>

Been learning F# for a while, I do like it. In Visual Studio 2017, for some reason on some .fs files I can open a module and it will work just fine in the editor. When I try to run scripts in F# interactive that rely on opening another module I get a ‘namespace or module is not defined error’. For some reason, it does not give me the same error when I open System. I’ve made sure to organizing it so that the required module to open comes before the script that wants to call it. It will work when I’m coding in the editor but breaks when I try to execute in interactive. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![FoggyFinder](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/foggyfinder/32/136_2.png) [@FoggyFinder](https://forums.fsharp.org/u/FoggyFinder)\
**Post date:** [May 24, 2019, 6:57am UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/2 "2019-05-24T06:57:14Z")

</div>

I’m quite rarely use F# Interactive but never seen such behaviour.  
I think it should work the same as in editor.

If you don’t get error when trying to get access to members of System namespace that probably means you already opened it somewhere.

If you can reproduce the issue, please share minimal sample of code. Then it will be much easier to understand where problem lays.

Just a note: F# has [AutoOpen](https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/core.autoopenattribute-class-%5Bfsharp%5D?f=255&MSPPError=-2147217396) attribute.

---

<div class="post-metadata">

**Author:** ![egp](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@egp](https://forums.fsharp.org/u/egp)\
**Post date:** [May 24, 2019, 9:57pm UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/3 "2019-05-24T21:57:30Z")

</div>

Looks like it may have been a noob mistake. I had to type in – #load into FSI for it to actually load the modules. Don’t have to do that in a normal .fs file, only in .fsx. This may just be normal.

---

<div class="post-metadata">

**Author:** ![mathias.brandewinder](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/mathias.brandewinder/32/10_2.png) [@mathias.brandewinder](https://forums.fsharp.org/u/mathias.brandewinder)\
**Post date:** [May 25, 2019, 12:23am UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/4 "2019-05-25T00:23:05Z")

</div>

From your description, it sounds like the module you want to use is not in your script, but in another file, either an `.fs` or `.fsx` file, is that correct? Something like `MyFile.fs`, with

```auto
module MyModule = 
    let hello (name: string) = sprintf "Hello, %s" name

```

Script files behave a bit differently from `.fs` files in a solution: they don’t belong to the solution, and are completely independent. If you want to use a resource that is in a different file, you have to explicitly import it. In this case, to use the `hello` function in a script, first you would `#load "path/to/MyFile.fs`, making the whole file contents available in your scripting environment, and then either `open MyModule`, or call `MyModule.hello "world"`.  
If you wanted to use a `dll`, you would similarly use `#r path/to/library.dll`.  
Note also that file order doesn’t matter for scripts, but load order might.  
Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![egp](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@egp](https://forums.fsharp.org/u/egp)\
**Post date:** [May 26, 2019, 12:21am UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/5 "2019-05-26T00:21:33Z")

</div>

Wow thanks for the detailed info! It makes sense, no problem now! I’m a C# developer and have fallen in love with F# and functional programming in general, it’s exciting to see a lively community behind the language.

---

<div class="post-metadata">

**Author:** ![systems](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/systems/32/585_2.png) [@systems](https://forums.fsharp.org/u/systems)\
**Post date:** [May 27, 2019, 4:43pm UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/6 "2019-05-27T16:43:51Z")

</div>

I would like to add that according to cartermp

> In the future, you’ll be able to `#r "package.name"`

> [@F# scripting, is this a supported use case?](https://forums.fsharp.org/t/f-scripting-is-this-a-supported-use-case/452/3):
>
> F# scripting is not supported with only .NET Core at this time. We’re working on bringing that up. That said, you can still script against the .NET Framework or Mono. Packages are installed into a .nuget folder on a machine, but the location of that folder may differ depending on the OS. You currently reference the .dll directly with #r. In the future, you’ll be able to #r "package.name" and no longer need to use#r` to point to a location on disk.

I dont know if we are there yet, I have been away from Fsharp for a while now  
but as per Mathias’ answer, it seems we are not there yet

> #r “package.name”

without having to point to a path, is huge in my opinion

---

<div class="post-metadata">

**Author:** ![jkone27](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/jkone27/32/735_2.png) [@jkone27](https://forums.fsharp.org/u/jkone27)\
**Post date:** [September 9, 2022, 12:33pm UTC](https://forums.fsharp.org/t/how-to-open-modules-in-f-interactive/822/7 "2022-09-09T12:33:24Z")

</div>

What about transitive dependencies between different scripts/modules/files in interactive ?  
how does that work? [F# interactive fails to load proper project "version" when using multiple scripts load · Issue #13866 · dotnet/fsharp · GitHub](https://github.com/dotnet/fsharp/issues/13866).
