ijrussell / essential-fsharp

Markdown source of Essential F# ebook
MIT License
110 stars 13 forks source link

Chapter 9 - Why use type abbreviation for 'Total' and 'DiscountPercentage'? #4

Closed bytesource closed 2 years ago

bytesource commented 2 years ago

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

ijrussell commented 2 years ago

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.

bytesource commented 2 years ago

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.