O'Reilly logo

Learn You a Haskell for Great Good! by Miran Lipovaca

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required