Arun Pandian M

Arun Pandian M

Android Dev | Full-Stack & AI Learner

Written by: Arun Pandian M•Published on: Nov 21, 2026

Records in Kotlin: Named Product Types

In Kotlin, data classes provide a powerful and idiomatic way to model named product types — a concept deeply rooted in functional programming and category theory. Understanding how these types work is essential for writing clean, maintainable, and expressive code.

What is a Product Type?

A product type is a type that combines multiple values into a single composite value. All components of the product type exist together — they are not alternatives, but rather parts of the same whole.

For example, a Car can be described by its model, manufacturer, and year. These are not separate entities, but they are all required for a complete representation of a car. This is a classic example of a product type.

In terms of structure, a product type can be thought of as:

String × String × Int

This represents a combination of a string (model), another string (manufacturer), and an integer (year). All components are required, and none are optional.

Records: Named Product Types

A record is a product type where each component has a name rather than being identified by position. This is a key distinction between records and tuples, which are positional in nature.

https://storage.googleapis.com/lambdabricks-cd393.firebasestorage.app/fp_record_data_img.svg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=firebase-adminsdk-fbsvc%40lambdabricks-cd393.iam.gserviceaccount.com%2F20261122%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20261122T215519Z&X-Goog-Expires=3600&X-Goog-SignedHeaders=host&X-Goog-Signature=0d0862f0d9d9d5ce056b910b6352994c5f23adf5089329b467b172e7c9896aa91324c4704693045be6d58bd8aa9e5826dbd1c4a75af5aa4b776e2977dd791115b3e48e7c70c2b8ed261a9ac7d157f01348d09775a93998a3c2fa8bc4266a2844bab1f550ae643f9cf9b9cef5b3a7efa3fa02e8aeb355f60cc6956057e3170ee2964d7a915e780948112546c2aa36046fee7049a90b4b5c88c5469b0b974a04b191437cc68fa66961b792ff51f214d4f1538b44e6344dee65e61e82217bd86bd01ab398383791bed91c41957087a946affbdc6395d9903f411b0de4cb7830a7ff7061190c5d24a1e468ddd406fccfcd618943087e82735cbd9b53ec0f71ec3b45

For example, the following is a tuple:

Triple("Swift", "Maruti", 2024)

Here, the meaning of each value is determined by its position in the tuple. This can make the code harder to read and maintain, especially as the number of components increases.

In contrast, a record provides clarity by assigning meaningful names to each component:

data class Car(
    val model: String,
    val manufacturer: String,
    val year: Int
)

This makes the code self-explanatory and reduces the risk of errors due to misinterpretation of position.

Kotlin Data Classes: Practical Named Product Types

Kotlin’s data class is a practical and idiomatic way to implement named product types. It automatically provides useful features like toString(), equals(), and copy(), making it ideal for modeling data structures.

Here’s how you might create an instance of a Car:

val car = Car(
    model = "Creta",
    manufacturer = "Hyundai",
    year = 2025
)

This is far more readable than using a Triple, and it clearly communicates the intent of the code.

Nested Product Types

Product types can also contain other product types. For example, a Car might have an Engine:

data class Engine(
    val horsepower: Int,
    val fuelType: String
)

data class Car(
    val model: String,
    val manufacturer: String,
    val year: Int,
    val engine: Engine
)

This structure is conceptually represented as:

Car
├── String
├── String
├── Int
└── Engine
    ├── Int
    └── String

This nesting of product types is a common and powerful technique in functional programming.

Product vs Coproduct

While product types represent the idea of AND (all components exist together), coproduct types represent the idea of OR (a value is one of several alternatives).

For example, a Vehicle can be either a Car or a Bike:

sealed interface Vehicle

data class Car(val model: String) : Vehicle

data class Bike(val model: String) : Vehicle

This is a coproduct type, and it represents the logical OR between Car and Bike.

The Category Theory Connection

From a theoretical perspective, product types are a foundational concept in category theory. A product combines multiple objects into one:

A × B

In the case of a Car, this becomes:

String × String × Int

By giving this product a meaningful name like Car, we are essentially naming a domain-specific structure that is isomorphic to the product type.

This is not just a syntactic convenience — it’s a semantic and structural equivalence.

Final Mental Model

When you see this Kotlin code:

data class Car(
    val model: String,
    val manufacturer: String,
    val year: Int
)

Think of it as:

Car
 ↓
A named product type
 ↓
String × String × Int
 ↓
All values exist together
 ↓
Each value has a meaningful name

This is the core idea behind records as product types — a concept that is both practical and deeply rooted in theoretical computer science.

Conclusion

Understanding records as named product types is essential for writing clean, expressive, and maintainable code in Kotlin. By using data classes, you are not just modeling data — you're modeling meaningful domain structures that are both readable and powerful.

This understanding is not only useful in Kotlin, but also in the broader context of functional programming and category theory, where product types are a fundamental building block.

#functionalprogramming#algebraicdatatypes#dataclasses#kotlin#fp#programming#namedproducttypes#producttypes#computerscience#typesystems#softwareengineering#categorytheory
LAMBDA BRICKS