monad.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/ext/boost/tuple.hpp>
  5. #include <boost/hana/tuple.hpp>
  6. #include <laws/applicative.hpp>
  7. #include <laws/base.hpp>
  8. #include <laws/functor.hpp>
  9. #include <laws/monad.hpp>
  10. #include <boost/tuple/tuple.hpp>
  11. namespace hana = boost::hana;
  12. template <int i>
  13. using eq = hana::test::ct_eq<i>;
  14. int main() {
  15. //////////////////////////////////////////////////////////////////////////
  16. // Setup for the laws below
  17. //////////////////////////////////////////////////////////////////////////
  18. auto eq_tuples = hana::make_tuple(
  19. ::boost::make_tuple()
  20. , ::boost::make_tuple(eq<0>{})
  21. , ::boost::make_tuple(eq<0>{}, eq<1>{})
  22. );
  23. auto eq_values = hana::make_tuple(eq<0>{}, eq<2>{});
  24. auto eq_tuples_tuples = hana::make_tuple(
  25. ::boost::make_tuple()
  26. , ::boost::make_tuple(
  27. ::boost::make_tuple(eq<0>{}))
  28. , ::boost::make_tuple(
  29. ::boost::make_tuple(eq<0>{}),
  30. ::boost::make_tuple(eq<1>{}, eq<2>{}))
  31. , ::boost::make_tuple(
  32. ::boost::make_tuple(eq<0>{}),
  33. ::boost::make_tuple(eq<1>{}, eq<2>{}),
  34. ::boost::make_tuple(eq<3>{}, eq<4>{}))
  35. );
  36. //////////////////////////////////////////////////////////////////////////
  37. // Functor up to Monad
  38. //////////////////////////////////////////////////////////////////////////
  39. hana::test::TestFunctor<hana::ext::boost::tuple_tag>{eq_tuples, eq_values};
  40. hana::test::TestApplicative<hana::ext::boost::tuple_tag>{eq_tuples};
  41. hana::test::TestMonad<hana::ext::boost::tuple_tag>{eq_tuples, eq_tuples_tuples};
  42. }