[hana]recursive data type?

How would one define a recursive data type in hana something described by the type equation: hana_list<T> = hana::nothing | std::pair<T,hana_list<T> > where hana_list<T> is a list of T's terminated by nothing?

On 06/24/2015 05:25 AM, Larry Evans wrote:
How would one define a recursive data type in hana something described by the type equation:
hana_list<T> = hana::nothing | std::pair<T,hana_list<T> >
where hana_list<T> is a list of T's terminated by nothing?
I think this: https://gist.github.com/cppljevans/f270db4ddeaf8bdd5733 would be a start.

Larry Evans <cppljevans <at> suddenlink.net> writes:
On 06/24/2015 05:25 AM, Larry Evans wrote:
How would one define a recursive data type in hana something described by the type equation:
hana_list<T> = hana::nothing | std::pair<T,hana_list<T> >
where hana_list<T> is a list of T's terminated by nothing?
I think this:
https://gist.github.com/cppljevans/f270db4ddeaf8bdd5733
would be a start.
Sorry for the late reply; you had the time to do it yourself! Indeed, what you wrote would be a good start. Then, you might want to make your List a model of some concepts, like Iterable: namespace boost { namespace hana { // This would require `_const<Head, Tail>` to inherit publicly from // `_pair<Head, Tail>`. template <> struct head_impl<List> { template <typename Head, typename Tail> static constexpr auto apply(_pair<Head, Tail> const& xs) { return hana::first(xs); } }; template <> struct tail_impl<List> { template <typename Head, typename Tail> static constexpr auto apply(_pair<Head, Tail> const& xs) { return hana::second(xs); } }; template <> struct is_empty_impl<List> { template <typename Xs> static constexpr auto apply(Xs const& xs) { return hana::bool_<!Xs::is_cons>; } }; }} However, note that a recursive implementation of a list might not lead to the best compile-time performance. Regards, Louis
participants (2)
-
Larry Evans
-
Louis Dionne