Product algebraic data types

In the simplest case, consider that I use the analogy of set product to combine types A and B; the result would be a set of data pairs where the first pair constituent is of type A, the second constituent is of type B, and the whole combination is a Cartesian product of A and B.

F# offers two product algebraic data types, that is, tuples and records.

Tuples

I have already touched tuples in previous chapters; now I'll go deeper into this subject.

Tuple composition

A tuple is a combination of two or more values of any type. The tuple value element type can be of anything: primitive types, other tuples, custom classes, and functions. For example, take a look at the following code line (Ch5_1.fsx):

let tuple = (1,"2",fun() ->3) ...

Get F# 4.0 Design Patterns 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.