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

Creating modules for reusable code - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

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…

Contents