Back to library

λMaster Haskell Typeclasses: From Functor to Monad

Climb the typeclass ladder one rung at a time - Eq, Show, Functor, Applicative, Monad - until real Haskell stops looking like runes, and you can ship a tiny expression DSL built on your own custom class.

Applied14 drops~2-week path · 5–8 min/daytechnology

Phase 1Typeclasses as Everyday Interfaces

See typeclasses as interfaces, not scary math.

4 drops
  1. A typeclass is a promise, not a type

    6 min

    A typeclass is a promise, not a type

  2. Haskell solves overloading without inheritance

    6 min

    Typeclasses give you overloading without a class hierarchy

  3. Every `=>` is a bouncer checking IDs

    7 min

    Constraints on the left of `=>` are capability checks, not types

  4. The classes you'll actually use, ranked

    7 min

    Eight typeclasses cover 90% of real Haskell

Phase 2Writing Your Own Instances

Write instances for Eq, Ord, and Show.

5 drops
  1. `deriving Eq` is free - until it isn't

    7 min

    Derived Eq is structural; sometimes you need it to be semantic

  2. `compare` is one function, not three

    6 min

    Implementing `compare` once gives you `<`, `<=`, `>`, and `>=` for free

  3. `show` isn't for users - it's for you

    7 min

    `Show` is a debugging tool; user output belongs to your own formatter

  4. A typeclass without laws is just a naming scheme

    7 min

    Typeclass laws are how instances earn their reuse

  5. Build a `Point` that earns Eq, Ord, and Show

    8 min

    Ten lines of instance code unlocks the entire standard library

Phase 3The Functor-Applicative-Monad Ladder

Follow the Functor-Applicative-Monad ladder through real code.

4 drops
  1. Your ops engineer leaves logs only in a `Maybe`

    8 min

    When you need to transform a value inside a context without unwrapping it, reach for `fmap`

  2. Three form fields, three `Maybe`s, one user

    8 min

    When you need to combine multiple wrapped values with a pure function, reach for `<*>`

  3. `lookup` chain that finally makes `>>=` click

    8 min

    When later computations depend on earlier values, reach for `>>=`

  4. Spot the ladder step in any real code

    8 min

    Functor transforms, Applicative combines, Monad sequences with dependency

Phase 4Ship a Tiny Expression DSL

Design and ship a small expression DSL.

1 drop
  1. Build a `Pretty` typeclass and print expressions with it

    20 min

    A custom typeclass is just a contract for your own domain

Frequently asked questions

What's the difference between a typeclass and an interface?
This is covered in the “Master Haskell Typeclasses: From Functor to Monad” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Do I really have to learn Functor before Monad?
This is covered in the “Master Haskell Typeclasses: From Functor to Monad” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why does Haskell want Applicative between Functor and Monad?
This is covered in the “Master Haskell Typeclasses: From Functor to Monad” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Can I define my own typeclass without losing my mind?
This is covered in the “Master Haskell Typeclasses: From Functor to Monad” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Is Monad actually about side effects, or something else?
This is covered in the “Master Haskell Typeclasses: From Functor to Monad” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.