Lesson 4: Breaking the laws!

Contents
  • Why typeclasses have laws
  • The Functor Laws
  • Identity
  • Composition
  • A backward pair
    • Exercise
  • Enter hedgehog
    • Exercise
  • Coming up

In this lesson, we’ll be talking about the laws of the Functor typeclass, why they exist, and how to enforce them. We’ll be using some variations of instances we’ve written in previous lessons, particularly of the Pair type and a Maybe-like type to illustrate both law-abiding instances and what it means to break the laws. We’ll use the property-testing library called hedgehog to ensure instances are well-behaved.

Sign up for access to the full page, plus the complete archive and all the latest content.