Lesson 12. Creating your own types

After reading lesson 12, you’ll be able to

  • Define type synonyms to clarify code
  • Create your own data type
  • Build types from other types
  • Work with complex types by using record syntax

In the preceding lesson, you learned how to use the basic types in Haskell. Now it’s time to start creating some types of your own. Creating types in Haskell is more important than in most other programming languages, even statically typed ones, as nearly every problem you solve will come down to the types you’re using. Even when using an existing type, you’ll often want to rename it to make understanding your programs easier. For example, take a look at this type signature:

areaOfCircle :: Double -> Double

This is a perfectly ...

Get Get Programming with Haskell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.