January 2018
Beginner to intermediate
312 pages
7h 22m
English
In F#, the way that types are defined and the way that they are constructed are very similar.
For example, to define a record type, we use curly braces and then name:type definitions for each field, like this:
| | type Person = {First:string; Last:string} |
To construct a value of this type, we use the same curly braces but use = to assign a value to a field, like this:
| | let aPerson = {First="Alex"; Last="Adams"} |
And to deconstruct a value of this type using pattern matching, we use the same syntax but this time on the left side of the equation, like this:
| | let {First=first; Last=last} = aPerson |
This code says that the values first and last will be set to the corresponding fields in the record. With records, we ...
Read now
Unlock full access