template <class MonoidTag>
struct monoid;
// Requires:
// publicly inherit from monoid_defaults<MonoidTag>
// struct mempty;
// struct mappend { template <class, class> struct apply; };
template <class MonadTag>
struct monoid_defaults
{
struct mconcat
{
template <class L>
struct apply
{
// unspecified
};
};
};
This is a typeclass for monoids. A monoid is an abstraction of a type and an associative operation (mappend) on it. The operation is required to have an identity element (mempty). Examples:
0 as identity and addition as operation1 as identity and multiplication as operationMonoids have a mconcat operation that takes a sequence of values and produces as sum value from it by repeatedly calling mappend.
For any MonoidTag, the operations are expected to meet the following requirements:
mappend<mempty, X> is equivalent to Xmappend<X, mempty> is equivalent to Xmappend<X, mappend<Y, Z>> is equivalent to mappend<mappend<X, Y>, Z>mconcat<L> is equivalent to boost::mpl::reverse_fold<L, mempty, mappend>Due to the way Metamonad handles versioning, the monoid template class has to be specialised in the mpllibs::metamonad::v1 namespace.
#include <mpllibs/metamonad/monoid.hpp>
using boost::mpl;
struct plus_tag : mpllibs::metamonad::tmp_tag<plus_tag> {};
template <>
struct monoid<plus_tag> : monoid_defaults<plus_tag>
{
typedef int0 mempty;
typedef lambda_c<a, b, plus<a, b>> mappend;
};
Copyright Abel Sinkovics (abel at elte dot hu) 2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt