Cover by Miran Lipovaca

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 7. Making Our Own Types and Type Classes

So far, we’ve run into a lot of data types: Bool, Int, Char, Maybe, and so on. But how do we make our own? In this chapter, you’ll learn how to create custom types and put them to work!

image with no caption

Defining a New Data Type

One way to make our own type is to use the data keyword. Let’s see how the Bool type is defined in the standard library.

data Bool = False | True

Using the data keyword like this means that a new data type is being defined. The part before the equal sign denotes the type, which in this case is Bool. The parts after the equal sign are value constructors. They specify the different values that this ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required