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