A domain model represents the entities, relationships, rules, and behavior of a real-world problem. F# makes modeling collaborative: developers and domain experts can explore ideas interactively with readable code and in-memory data, then move a working model into a console application or ASP.NET Core web API. section 1.5.1
Strong domain modeling makes business rules explicit in types. Specific types can encode invariants, improve readability, and prevent accidentally mixing values that happen to share a representation, such as separate City and Country wrapper types even when both contain strings. section 1.5.2
F# provides complementary tools for expressing a domain:
- Use tuples and records to group related values and describe structured entities. section 9.4
- Use discriminated unions to represent alternatives and mutually exclusive cases, such as passenger or buffet carriages. section 8.0 section 9.4
- Use pattern matching and conditional logic to perform behavior over the modeled values. section 8.4 section 8.0
A train inventory domain
Model a train as carriages, an identification code, origin and destination stops, intermediate stops, and optional driver-change information. Represent carriage features such as quiet seating, Wi-Fi, and washrooms; distinguish first- and second-class passenger carriages; and allow buffet cars to serve hot food, cold food, or both. Then define operations for total seats, travel time between stops, and locating carriages with a requested feature. section 9.4







