liveBook · Manning

Product type

As explained in Functional Design and Architecture: Examples in Haskell

A product type combines multiple component values into one composite value, such as a tuple or record.

When a domain value must carry several related pieces of information, a product type combines them into one composite value. A tuple groups components positionally, while a record names its fields. Functional domain models commonly use these structures as building blocks for algebraic data types. section 2.1.2

A person as a composite value

PersonName = (String, String) represents a first and last name as a tuple. Person then combines that product with an age field: Person { name :: PersonName, age :: Age }. The result keeps related data together while preserving its domain structure. section 2.1.2

type PersonName = (String, String)
johnDoeName, janeDoeName :: PersonName
johnDoeName = ("John", "Doe")
janeDoeName = ("Jane", "Doe")

Inspect the tuple definition and concrete names that demonstrate a product type built from two components. section 2.1.2

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines tuples and records as product types and places them within algebraic data types, without detailing implementation semantics.
Examples
Demonstrates product types through PersonName tuples and Person records containing names and ages.
What you can do after
Build it from scratch by combining related values into tuple- or record-shaped domain types.
How it connects
Connects product types with sum types, algebraic data types, domain models, and immutable data structures.

Also explained in

Compare how 2 books explain product type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.