O'Reilly logo

Domain Modeling Made Functional by Scott Wlaschin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required