template <class MonadTag>
struct monad;
  // Requires:
  //   publicly inherit from monad_defaults<MonadTag>
  //   struct return_ { template <class> struct apply; };
  //   struct bind { template <class, class> struct apply; };

template <class MonadTag>
struct monad_defaults
  struct bind_
    template <class A, class B>
    struct apply
      // unspecified


This is a typeclass for monads. For a monad a set of template metaprogramming values has to be (informally) specified. This set of values is called the monadic values. The typeclass requires the following operations to be implemented:

For any MonadTag, the operations are expected to meet the following requirements:

The typeclass implements the following operation:

Due to the way Metamonad handles versioning, the monad template class has to be specialised in the mpllibs::metamonad::v1 namespace.

#include <mpllibs/metamonad/monad.hpp>


using boost::mpl;

struct join_lists
  template <class State, class NewList>
  struct apply :
      typename end<State>::type,

struct list_tag;

template <>
struct monad<list_tag> : monad_defaults<list_tag>
  struct return_
    template <class T>
    struct apply : list<T> {};
  struct bind
    template <class A, class F>
    struct apply : fold<typename transform<A, F>::type, list<>, join_lists> {};