Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:58

0001 /*!
0002 @file
0003 Forward declares `boost::hana::MonadPlus`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_CONCEPT_MONAD_PLUS_HPP
0011 #define BOOST_HANA_FWD_CONCEPT_MONAD_PLUS_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 
0015 
0016 namespace boost { namespace hana {
0017     //! @ingroup group-concepts
0018     //! @defgroup group-MonadPlus MonadPlus
0019     //! The `MonadPlus` concept represents Monads with a monoidal structure.
0020     //!
0021     //! Intuitively, whereas a Monad can be seen as some kind of container
0022     //! or context, a MonadPlus can be seen as a container or a context that
0023     //! can be concatenated with other containers or contexts. There must
0024     //! also be an identity element for this combining operation. For example,
0025     //! a tuple is a MonadPlus, because tuples can be concatenated and the
0026     //! empty tuple would act as an identity for concatenation. How is this
0027     //! different from a Monad which is also a Monoid? The answer is that the
0028     //! monoidal structure on a MonadPlus must _not_ depend of the contents
0029     //! of the structure; it must not require the contents to be a Monoid
0030     //! in order to work.
0031     //!
0032     //! While sequences are not the only possible model for MonadPlus, the
0033     //! method names used here refer to the MonadPlus of sequences under
0034     //! concatenation. Several useful functions generalizing operations on
0035     //! sequences are included with this concept, like `append`, `prepend`
0036     //! and `filter`.
0037     //!
0038     //! @note
0039     //! This documentation does not go into much details about the nature
0040     //! of the MonadPlus concept. However, there is a nice Haskell-oriented
0041     //! [WikiBook][1] going into further details.
0042     //!
0043     //!
0044     //! Minimal complete definition
0045     //! ---------------------------
0046     //! `concat` and `empty`
0047     //!
0048     //!
0049     //! Laws
0050     //! ----
0051     //! First, a MonadPlus is required to have a monoidal structure. Hence, it
0052     //! is no surprise that for any MonadPlus `M`, we require `M(T)` to be a
0053     //! valid monoid. However, we do not enforce that `M(T)` actually models
0054     //! the Monoid concept provided by Hana. Further, for all objects `a, b, c`
0055     //! of data type `M(T)`,
0056     //! @code
0057     //!     // identity
0058     //!     concat(empty<M(T)>(), a) == a
0059     //!     concat(a, empty<M(T)>()) == a
0060     //!
0061     //!     // associativity
0062     //!     concat(a, concat(b, c)) == concat(concat(a, b), c)
0063     //! @endcode
0064     //!
0065     //! Secondly, a MonadPlus is also required to obey the following laws,
0066     //! which represent the fact that `empty<M(T)>()` must be some kind of
0067     //! absorbing element for the `chain` operation. For all objects `a` of
0068     //! data type `M(T)` and functions @f$ f : T \to M(U) @f$,
0069     //! @code
0070     //!     chain(empty<M(T)>(), f)         == empty<M(U)>()
0071     //!     chain(a, always(empty<M(T)>())) == empty<M(U)>()
0072     //! @endcode
0073     //!
0074     //!
0075     //! Refined concepts
0076     //! ----------------
0077     //! `Functor`, `Applicative` and `Monad`
0078     //!
0079     //!
0080     //! Concrete models
0081     //! ---------------
0082     //! `hana::optional`, `hana::tuple`
0083     //!
0084     //! [1]: https://en.wikibooks.org/wiki/Haskell/MonadPlus
0085     template <typename M>
0086     struct MonadPlus;
0087 }} // end namespace boost::hana
0088 
0089 #endif // !BOOST_HANA_FWD_CONCEPT_MONAD_PLUS_HPP