liveBook · Manning

File and symbol ordering

As explained in F# in Action: A Revised Edition of Get Programming with F#

File order is the project-defined ordering of F# source files that determines which declarations and dependencies are visible during compilation.

F# uses a deliberate order for files and declarations. That order determines which code is available during compilation and makes dependencies easier to follow instead of allowing circular, spaghetti-like relationships. section 6.2.3 section 3.2.4

Place low-level, independent files first and files that consume them later. For example, a database-access file such as Db.fs can precede higher-level code, while Program.fs is placed last because it uses declarations from the other files. section 6.2.3

Figure 6.5 A typical F# project file, with the last file declared that can access all other files

A project-file view makes the compilation order visible: the final file can access declarations from the files above it. section 6.2.3

Do not confuse display order with compilation order. VS Code’s standard explorer sorts files alphabetically, whereas Ionide provides a panel showing the logical order defined by the project file. section 6.2.3

Use ordering as a practical development aid:

  • Read dependencies downward through the project: later files can use earlier declarations. section 6.2.3
  • When many compiler errors appear, fix the first error in the first file before addressing downstream messages. section 3.2.4
  • Use temporary type annotations when inference obscures the location of the original problem, then remove them after correcting the error. section 3.2.4

A small application

Define a Car module and its drive function in an earlier file, then call it from Program.fs: `let remaining = Car.drive 2 8` followed by `printfn $"You have {remaining} gas left."`. The ordering makes the function available where it is used. section 6.2.3

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains file and symbol constraints, project-tool displays, and first-error diagnosis without descending into compiler internals.
Examples
Uses Db.fs, Program.fs, Car.drive, Ionide’s logical-order panel, and a small gas-calculation application.
What you can do after
Diagnose compiler failures by correcting the earliest error and inspect logical file order with Ionide.
How it connects
Connects modules, declarations, dependencies, project files, type inference, and compiler errors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.