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, ...
Get Domain Modeling Made Functional now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.