A cyclical dependency is a reference loop: A needs B, B needs C, and C eventually needs A. F# normally avoids these loops by requiring a symbol to be declared before another declaration can reference it. This creates a clear dependency order instead of tangled, mutually dependent code. section 3.1.3
This ordering makes code easier to work with:
- Read upward to find what a function depends on, and downward to find possible callers. section 3.1.3
- Order files the same way: an earlier F# file cannot reference code in a later file. section 3.1.3
- Treat compiler errors from forward references as a prompt to reorder or redesign the dependency. section 3.1.3
A forward reference
Here, description tries to use employee before employee exists. Declare employee first, then build description from it. The same principle prevents longer reference loops. section 3.1.3
let description = $"{employee} lives in New York." #1
let employee = "Joe Bloggs"
Inspect the out-of-order declarations that trigger the restriction. section 3.1.3
