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 modules for reusable code - ReasonML Tutorial
From the course: ReasonML: First Look
Creating modules for reusable code
- [Instructor] In this course we'll be using the cake size type for many examples. We'd like some way to use it without having to copy and paste the source into all of our programs. We're in luck! Every source file in Reason can be used as a module by other files. The module name is the same as the file name and it must begin with a capital letter. Our file name does, so we're in business. Let's right some code that uses that module. As long as it's in the same directory as the cake sized dot re file everything will work fine. We'll create a variable called my cake and set it's value to half. That comes from the cake size module, so we have to specify that. Our development environment shows the fully qualified type name, which includes the project directory modules, but we don't have to type that part ourselves. Here's a function called get lower price that takes a size, which is the cake size type from the cake size…
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)
-
-