Using primitive types

65 views
Skip to first unread message

Quang

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

Matthew Browne

unread,
Jun 19, 2020, 2:42:33 PM6/19/20
to object-co...@googlegroups.com, 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:
https://www.youtube.com/watch?v=Up7LcbGZFuo


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 object-composit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/object-composition/b343828e-8b41-4b1c-91d7-658196e0e301o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages