Functortown: A Map of the Territory

This course will be a full tour of the functors. We will start by examining the motivation for functors and the Functor typeclass. From there, we’ll explore monoidal functors, bifunctors, contravariant functors, and profunctors in depth, discussing the laws and the mathematical basis for these structures along the way.

Topics covered in this course:

  • Functor, Bifunctor, Applicative, Traversable, Monad, Contravariant, and Profunctor typeclasses;
  • type constructors and higher kindedness;
  • representative instances and uses of each;
  • the laws and how to property test your instances using the hedgehog testing library.

Prerequisites:

  • knowledge of several basic types, especially Maybe, Either, tuples, and the function type;
  • basic understanding of typeclasses and their relationship with types; and
  • some facility with Haskell syntax.

Lesson plan

Part I: Functor

Part II: Bifunctor

Part III: Applicative


Not yet written

  • A functor but not an applicative
  • The function applicative and Reader
  • Applicatives compose
  • The Applicative laws and property tests
  • A monoid for applicative functors

Part IV: Traversable

  • Introduction: what and why
  • Instances
  • Connection to Applicative
  • Examples of traverse usage
  • The Traversable laws and property tests

Part V: Monad

  • Introduction: what and why
  • Instances
  • Relationship to Functor and Applicative
  • Examples of >>= usage
  • The Kleisli fish
  • The Reader newtype
  • The Monad laws and property tests
  • Monads do not compose: monad transformers

Part VI: Contravariant

  • Introduction: what and why
  • What kinds of types are contravariant
  • Relationship to an earlier functor
  • Examples of contramap usage
  • The Contravariant laws and property tests

Part VII: Profunctor

  • Introduction: what and why
  • Breaking down dimap
  • What kinds of types are profunctors
  • Examples, from basic to complex
  • The Profunctor laws and property tests

Join Type Classes for courses and projects to get you started and make you an expert in FP with Haskell.