diff --git a/include/boost/hana/detail/sandbox/bottom.hpp b/include/boost/hana/detail/sandbox/bottom.hpp new file mode 100644 index 000000000..c3a161724 --- /dev/null +++ b/include/boost/hana/detail/sandbox/bottom.hpp @@ -0,0 +1,27 @@ +/*! +@file +Defines `boost::hana::Bottom`. + +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_BOTTOM_HPP +#define BOOST_HANA_BOTTOM_HPP + +#include +#include + + +namespace boost { namespace hana { + //! @ingroup datatypes + //! The `Bottom` data type represents statically type-erased data. + struct Bottom { }; + + BOOST_HANA_CONSTEXPR_LAMBDA auto bottom = [](auto x) { + return detail::wrap(x); + }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_BOTTOM_HPP diff --git a/include/boost/hana/detail/sandbox/traversable.hpp b/include/boost/hana/detail/sandbox/traversable.hpp new file mode 100644 index 000000000..1392e7693 --- /dev/null +++ b/include/boost/hana/detail/sandbox/traversable.hpp @@ -0,0 +1,90 @@ +/*! +@file +Defines `boost::hana::Traversable`. + +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_TRAVERSABLE_HPP +#define BOOST_HANA_TRAVERSABLE_HPP + +#include +#include + + +namespace boost { namespace hana { + BOOST_HANA_TYPECLASS_BOILERPLATE(struct Traversable) + + /*! + @ingroup typeclasses + `Traversable` represents types that can be folded in a + structure-preserving manner. + + -------------------------------------------------------------------------- + + ## Laws + + */ + struct Traversable : typeclass { + struct traverse_mcd; + }; + + //! Structure-preserving left-fold with an `Applicative`. + //! @method{Traversable} + //! + //! ### Example + //! @todo + BOOST_HANA_CONSTEXPR_LAMBDA auto traverse = [](auto f, auto traversable) { + return Traversable::instance< + datatype_t + >::traverse_impl(f, traversable); + }; + + //! Minimal complete definition: `traverse` + struct Traversable::traverse_mcd { + + }; + + template <> + struct Traversable::instance : Traversable::traverse_mcd { + template class A, typename Y> + static constexpr auto traverse_impl(Function> f, Maybe mx) { + return maybe( + lift(nothing), + [](auto x) { return ap(lift(just), f(x)); }, + mx + ); + } + + template + static constexpr auto traverse_impl(F f, M m) { + using A = datatype_t; + nothing -> lift(nothing) + just(x) -> ap(lift(just), f(x)) + } + }; + + template <> + struct Traversable::instance : Traversable::traverse_mcd { + template class A, typename Y> + static constexpr auto traverse_impl(Function> f, List xs) { + auto cons_f = [=](auto x, auto ys) { + return ap(ap(lift(cons), f(x)), ys); + }; + return foldr(cons_f, lift(list()), xs); + } + + template + static constexpr auto traverse_impl(F f, Xs xs) { + using A = ???; + auto cons_f = [=](auto x, auto ys) { + return ap(ap(lift(cons), f(x)), ys); + }; + return foldr(cons_f, lift(list()), xs); + } + }; +}} // end namespace boost::hana + +#endif // !BOOST_HANA_TRAVERSABLE_HPP