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.

Using collection types

Using collection types - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

Using collection types

- [Instructor] Up to now, we've been working with individual variables. Reason has three ways to make collections of data. Tuples, which have fixed length and whose items can have different data types, lists, which don't have a fixed length but are immutable and whose elements must all be the same type, and arrays. For our first look, we'll investigate arrays, which are the closest to their JavaScript equivalent. To make an array in Reason, you put the items, separated by commas, between square brackets and vertical bars. Here is an array of integers. In Reason, all the elements in an array must have the same data type. To access an element in the array, you put its index number in square brackets. This will give us 11 because index numbers for an array begin at zero. Using an index number in brackets isn't entirely safe. If the index is out of bounds, your program will throw an exception. A safer way to get elements…

Contents