Creating Modules
Just as there’s not a lot to defining records, there’s not much to the basics of modules. In fact, we’ve been working with modules all along—any re file is automatically a module, as we saw when we put the shirt size data type and its associated functions in a separate file. You can also create a module within a file by using the keyword module, the module name (which must begin with a capital letter), an equal sign, and then code in braces. Anything you could put in a ReasonML file can be in a module definition.
So let’s expand our type definitions and add utility functions for converting to and from strings in our types, each of which will be in its own mini-module. First, let’s look at the Size module:
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.