Modules

An F# construct for grouping values, types and functions.

This is the primrary code organization construct in F#. Libraries and multi-file applications require all files to start with a namespace or module definition.

One recomendation is to use a top-level namespace followed by the module name. For example:

1: 
2: 
3: 
module MyApp.MyModule

let

modules/implicit.fsx

1: 
2: 
#load "modules/implicit.fsx"
let myX = Implicit.x

Local module declarations require indentation. These modules would also be implicitly grouped in a top-level module Program if the file is program.fs:

modules/local.fsx

1: 
#load "modules/local.fsx"

This can be referenced:

1: 
2: 
3: 
4: 
let result1 = Local.Outer.Inner.xFunc 5 // => 15

open Local.Outer.Inner
let result2 = xFunc 5 // => 15

Modules, as with namespaces can be mutually recursive:

1: 
2: 
3: 
4: 
5: 
6: 
module rec MutualReferences =
  exception DontSqueezeTheBananaException of Banana

  type Banana() =
    // ...
    member self.SqueezeJuiceOut() = raise (DontSqueezeTheBananaException self)