Introduction

A type class defines some types related by their operations. This is saying that typeclasses are usually defined in terms of those operations, and these operations group those type together.

For example, we can put all types that can be converted to a String in the same type class called Show .

We can introduce this Show type class by:

  1. class Show a where
  2. show :: a -> String

Then we can give an instance to the type class.

  1. instance Show String where
  2. show s = s
  3. instance Show Boolean where
  4. show true = "true"
  5. show false = "false"