Modeling Simple Values
Let’s first look at the building blocks of a domain: simple values.
As we found out when we gathered the requirements, a domain expert does not generally think in terms of int and string but instead in terms of domain concepts such as OrderId and ProductCode. Furthermore, it’s important that OrderIds and ProductCodes don’t get mixed up. Just because they’re both represented by ints, say, doesn’t mean that they are interchangeable. So to make it clear that these types are distinct, we’ll create a “wrapper type”—a type that wraps the primitive representation.
As we mentioned earlier, the easiest way to create a wrapper type in F# is to create a “single-case” union type, a choice type with only one choice.
Here’s an example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access