From the course: ReasonML: First Look

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating record types

Creating record types - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

Creating record types

- [Instructor] There's more to a cake than its size. There's the flavor of the cake, the frosting, the number of layers, the filling if you have multiple layers, and the all important message. We'll want to create a data type for each of these. The cake size, the flavor, the frosting, and filling. But we don't want to make separate files for each of them. Instead, we can create modules within one file with the module keyword. Here they are, each with a to string and from string function. I've collapsed the view of the functions, so you can see the pattern more clearly. Here's the size module, flavor, frosting, and filling. All of these pieces of data belong together to describe a cake. And in Reason, we use a record type to put them all together. We're in the Cake.re file, so the module name is cake. We'll define a type t, which will be a record that consists of these fields separated by commas, a size, which is a…

Contents