Capturing Business Rules in the Type System
Let’s look at another modeling challenge: can we document business rules using just the type system? That is, we’d like to use the F# type system to represent what is valid or invalid so that the compiler can check it for us, instead of relying on runtime checks or code comments to ensure the rules are maintained.
Here’s a real-world example. Suppose our company, Widgets Inc, stores email addresses for its customers. But let’s also suppose not all email addresses should be treated the same way. Some email addresses have been verified—that is, the customer got a verification email and clicked on the verification link—while other email addresses aren’t verified and we can’t be sure they’re valid. Furthermore, ...
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