March 2019
Intermediate to advanced
208 pages
5h 11m
English
Shirt sizes don’t end with extra-large. There are double, triple, and even quadruple extra-large, usually abbreviated as XXL, XXXL, and XXXXL. Parameterized types let us specify a parameter for the constructor. In our case, we want the parameter to tell us how many Xs are on the shirt size. Here’s a parameterized version of the shirt size constructor (it has the same name, but it’s in a separate file):
| | type shirtSize = |
| | | Small |
| | | Medium |
| | | Large |
| | | XLarge(int); |
The last line says that to construct an XLarge variant, you need to provide an integer, which we’ll use to tell how many “extras” we want:
| | let mySize ... |
Read now
Unlock full access