March 2019
Intermediate to advanced
208 pages
5h 11m
English
To create a list, you um… list the elements within square brackets. Unlike tuples, whose elements may be of different types, a list’s elements must all have the same type. Lists in ReasonML are immutable. Once you create a list, you can’t change the contents of an individual element. Instead, all of the list manipulation functions we’ll look at return a brand-new list. Let’s create and display a short list of integers:
| | let example = [10, 11, 12]; |
| | Js.log(example); |
With this rather surprising result:
| | you@computer:~/book_projects/collections> node src/IntList.bs.js |
| | [ 10, [ 11, [ 12, 0 ] ] ] |
What we’re seeing is a reflection of the internal form of a list. If we had more than three elements ...
Read now
Unlock full access