Creating Data Types and Records
One of the most common reasons to make your own data types in Haskell is to create named and structured collections of some other types. For example, you might want to create a type that represents some information about a customer like their first and last name, the number of products they’ve ordered, and their current outstanding account balance. You can create a new type with the data keyword. For example, to create a new CustomerInfo you can simply say:
| data CustomerInfo |
This defines the existence of a new type called CustomerInfo. Unfortunately, as we’ve written the code, the only thing it does is define a new type. We don’t have any way to create a value of our new type, in other words we’ve created ...
Get Effective Haskell 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.