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 - ReasonML Tutorial
From the course: ReasonML: First Look
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Creating your own data types5m 10s
-
(Locked)
Say goodbye to null and undefined4m 39s
-
(Locked)
Creating modules for reusable code2m 35s
-
(Locked)
Using collection types6m 41s
-
(Locked)
Creating record types6m 47s
-
(Locked)
Challenge: Generating random cakes2m 1s
-
(Locked)
Solution: Generating random cakes2m 57s
-
(Locked)
-
-