Using primitive types

Skip to first unread message


Jun 17, 2020, 12:56:30 AM6/17/20
to object-composition

Matthew Browne

Jun 19, 2020, 2:42:33 PM6/19/20
to, Quang

There is a similar approach in the book "Domain Modeling Made Functional" by Scott Wlaschin. Some examples from the book:

type CheckNumber = CheckNumber of int
type CardNumber = CardNumber of string

type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo

type PaymentAmount = PaymentAmount of decimal
type Currency = EUR | USD

type Payment = {
  Amount: PaymentAmount
  Currency: Currency
  Method: PaymentMethod

(The solutions used in the book are intended for a type system like that of F# or OCaml, but but it looks like the same general concept as the Medium article.)

Unfortunately I didn't finish reading the book and haven't tried its examples in any real apps, so I can't speak to how well this works in practice, but it makes sense to me.

There's also a video by the author that I posted a while back:

On 6/17/20 12:56 AM, Quang wrote:
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages