Skip to content

Instantly share code, notes, and snippets.

@kris-jusiak
Created June 18, 2015 10:55
Show Gist options
  • Save kris-jusiak/bfc51747d083e140772d to your computer and use it in GitHub Desktop.
Save kris-jusiak/bfc51747d083e140772d to your computer and use it in GitHub Desktop.
Hana - Compilation Error -> MonadPlus not satisfied
#include <type_traits>
#include <boost/hana.hpp>
namespace hana = boost::hana;
template<class>
struct yet { };
template<typename T>
struct some_magic {
using type = decltype(
hana::second(
hana::fold(
hana::range_c<int, 1, 5>
, hana::make_pair(hana::make_tuple(yet<T>{}), hana::make_tuple())
, [](auto result, auto) {
auto is_construcrible =
hana::partial(hana::flip(hana::unpack), hana::trait<std::is_constructible>);
auto which = hana::if_(
is_construcrible(hana::append(hana::type<T>, hana::first(result)))
, hana::first
, hana::second
);
return hana::make_pair(
hana::prepend(hana::first(result), hana::type<yet<T>>)
, which(result)
);
}
)
)
);
};
int main() {
using type = typename some_magic<int>::type;
}
//clang++ -std=c++1y error.cpp -I hana/include
//In file included from error.cpp:2:
//In file included from hana/include/boost/hana.hpp:20:
//In file included from hana/include/boost/hana/foldable.hpp:39:
//In file included from hana/include/boost/hana/monad_plus.hpp:13:
//hana/include/boost/hana/fwd/monad_plus.hpp:305:13: error: static_assert failed "hana::append(xs, x) requires 'xs' to be a MonadPlus"
//static_assert(_models<MonadPlus, M>{},
//^ ~~~~~~~~~~~~~~~~~~~~~~~
//error.cpp:21:42: note: in instantiation of function template specialization 'boost::hana::_append::operator()<const boost::hana::_type<int>::_ &, boost::hana::_tuple<yet<int> > >' requested here
//is_construcrible(hana::append(hana::type<T>, hana::first(result)))
//^
//hana/include/boost/hana/detail/variadic/foldl1.hpp:61:26: note: in instantiation of function template specialization 'some_magic<int>::(anonymous
//class)::operator()<boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> >, boost::hana::_integral_constant<int, 1> >' requested here
//return f(f(f(f(static_cast<X1&&>(x1),
//^
//hana/include/boost/hana/detail/variadic/foldl1.hpp:201:52: note: in instantiation of function template specialization 'boost::hana::detail::variadic::foldl1_impl<5, boost::hana::when<true>
//>::apply<some_magic<int>::(lambda at error.cpp:16:17), boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> >, boost::hana::_integral_constant<int, 1>,
//boost::hana::_integral_constant<int, 2>, boost::hana::_integral_constant<int, 3>, boost::hana::_integral_constant<int, 4> >' requested here
//return foldl1_impl<sizeof...(xn) + 1>::apply(
//^
//hana/include/boost/hana/functional/partial.hpp:69:20: note: in instantiation of function template specialization 'boost::hana::detail::variadic::_foldl1::operator()<some_magic<int>::(lambda at error.cpp:16:17),
//boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> >, boost::hana::_integral_constant<int, 1>, boost::hana::_integral_constant<int, 2>, boost::hana::_integral_constant<int, 3>,
//boost::hana::_integral_constant<int, 4> >' requested here
//return detail::std::move(f)(
//^
//hana/include/boost/hana/range.hpp:112:20: note: in instantiation of function template specialization 'boost::hana::_partial<boost::hana::detail::variadic::_foldl1,
//boost::hana::detail::closure_impl<boost::hana::detail::element<0, some_magic<int>::(lambda at error.cpp:16:17)>, boost::hana::detail::element<1, boost::hana::_pair<boost::hana::_tuple<yet<int> >,
//boost::hana::_tuple<> > > > >::operator()<boost::hana::_integral_constant<int, 1>, boost::hana::_integral_constant<int, 2>, boost::hana::_integral_constant<int, 3>, boost::hana::_integral_constant<int, 4>
//>' requested here
//return static_cast<F&&>(f)(_integral_constant<T, from + v>{}...);
//^
//hana/include/boost/hana/range.hpp:117:20: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
//return unpack_helper<T, from>(static_cast<F&&>(f),
//^
//hana/include/boost/hana/fwd/foldable.hpp:1378:28: note: in instantiation of function template specialization 'boost::hana::unpack_impl<boost::hana::Range, void>::apply<int, 1, 5,
//boost::hana::_partial<boost::hana::detail::variadic::_foldl1, boost::hana::detail::closure_impl<boost::hana::detail::element<0, some_magic<int>::(lambda at error.cpp:16:17)>,
//boost::hana::detail::element<1, boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> > > > > >' requested here
//return Unpack::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f));
//^
//hana/include/boost/hana/foldable.hpp:56:20: note: in instantiation of function template specialization 'boost::hana::_unpack::operator()<const boost::hana::_range<int, 1, 5> &,
//boost::hana::_partial<boost::hana::detail::variadic::_foldl1, boost::hana::detail::closure_impl<boost::hana::detail::element<0, some_magic<int>::(lambda at error.cpp:16:17)>,
//boost::hana::detail::element<1, boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> > > > > >' requested here
//return hana::unpack(static_cast<Xs&&>(xs),
//^
//hana/include/boost/hana/fwd/foldable.hpp:295:30: note: in instantiation of function template specialization 'boost::hana::fold_left_impl<boost::hana::Range, boost::hana::when<true> >::apply<const
//boost::hana::_range<int, 1, 5> &, boost::hana::_pair<boost::hana::_tuple<yet<int> >, boost::hana::_tuple<> >, some_magic<int>::(lambda at error.cpp:16:17)>' requested here
//return FoldLeft::apply(static_cast<Xs&&>(xs),
//^
//error.cpp:13:13: note: in instantiation of function template specialization 'boost::hana::_fold_left::operator()<const boost::hana::_range<int, 1, 5> &, boost::hana::_pair<boost::hana::_tuple<yet<int> >,
//boost::hana::_tuple<> >, some_magic<int>::(lambda at error.cpp:16:17)>' requested here
//hana::fold(
//^
//error.cpp:37:27: note: in instantiation of template class 'some_magic<int>' requested here
//using type = typename some_magic<int>::type;
//^
//In file included from error.cpp:2:
//In file included from hana/include/boost/hana.hpp:20:
//In file included from hana/include/boost/hana/foldable.hpp:39:
//In file included from hana/include/boost/hana/monad_plus.hpp:13:
//hana/include/boost/hana/fwd/monad_plus.hpp:309:28: error: call to deleted member function 'apply'
//return Append::apply(static_cast<Xs&&>(xs), static_cast<X&&>(x));
//~~~~~~~~^~~~~
//hana/include/boost/hana/detail/dispatch_if.hpp:19:31: note: candidate function [with T = <const boost::hana::_type<int>::_ &, boost::hana::_tuple<yet<int> >>] has been explicitly deleted
//static constexpr auto apply(T&& ...) = delete;
//^
//2 errors generated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment