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 ...

Get Web Development with ReasonML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.