Steps
Steps to learning Reason OCaml

Myer Nore
Feb 23, 2018 - 3 min read

Records

Intro to Record Types

A Record is a declaration of a new datastructure with certain fixed attributes. To make a new Record type, use the type keyword with the curly braces:

/* loading */

Here, bool is the ReasonML boolean, and string is the ReasonML string.

Record types are rigid; after declaration, you cannot add, remove or change the record type's attributes.

Record type names and their attributes are expected to be lowercase.

This example comes from the excellent talk Domain Modeling Made Functional by Scott Wlaschin. We will revisit and improve this type as more of ReasonML is uncovered in future posts.

Record Examples

Update a Record with the spread operator

/* loading */

The update syntax using the spread operator "..." returns a new object with the previous properties copied in. This is called "immutable update" because the previous object is not changed in memory; instead, a new object is created.

Image Credit: Records by Thomas on Flickr

Edit this post here