Chapter 3Creating Your Own Data Types
In this chapter, you will learn how to go beyond ReasonML’s built-in data types such as int, float, and string by defining your own data types. This powerful capability will help you build reliable, robust programs. In addition to letting you express your programs in terms that mirror your data structures, data types give you these extra advantages:
-
You can create data types such as Price or Discount to ensure type safety—the compiler will make sure you can’t ever pass a Discount as an argument to a function that expects a Price.
-
You can create variant data types that specify a set of valid values. For example, in a survey, you might define a type with values Agree, Disagree, and Neutral. ReasonML’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access