Chapter 9 - Why use type abbreviation for 'Total' and 'DiscountPercentage'?
bytesource opened this issue · comments
Hi Ian,
After you mentioning the problems with type abbreviations compared to (private) singe-case discriminated unions, I wonder why you chose type abbreviations for Spend
and DiscountPercentage
on page 128:
type Total = decimal
type DiscountPercentage = decimal
Was this merely to keep the book code a bit shorter, or is there something else I should keep in mind?
Still enjoying your book!
Cheers,
Stefan
It was mainly for brevity but there wasn't any obvious benefit in these cases (function outputs) from using something more complex. Converting them into single-case DUs is relatively easy should you feel the urge to do so.
Thanks, that makes sense. I converted Total
to a single-case DU, but kept DiscountPercentage
as a type abbreviation, as in the example code it's only used internally.