Computer Laboratory

Indexed monads

Indexed monads are a generalisation of monads where, from a functional programming perspective, a monadic type constructor is annotated (indexed) by another type representing effect information that explains the effects of a computation, i.e., values of type M r a are effectul computations of values of type a with effects r. They provide a way to give finer-grained information about impurity and capture a greater class of effectul computations that normal monads.

In Haskell, indexed monads are defined something like:

class IxMonad (m :: * -> * -> *) where

   type Unit m 
   type Plus m s t

   return :: a -> m (Unit m) a
   (>>=) :: m s a -> (a -> m t b) -> m (Plus m s t) b

where the type-level function Unit describes the trivial "pure" effect, and Plus combines effect information from subcomputations. These form a monoid.

Slides

Code

References