|
Boost : |
Subject: [boost] Boost.Hana - Maybe and Either data types design
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-09-21 03:37:22
Hi Louis,
I have some concerns with the design of the Maybe and Either data types
(maybe the other data types have the same design, I have not taken a
look at).
There are somethings that I don't understand, sorry I have not changed
yet my mind to then new C++ way.
If I want to define a function that takes an Either string int, how can
I define it?
void f(??? p) {}
I see that there is a maybe_detail::maybe<bool,class>, however I don't
think this is the data type of Maybe, is it?
Anyway, I don't see a either_detail::either<bool, class, class>.
I have the impression that I must use always auto with lambdas
auto f = [](auto p) {...};
But I don't know what I can put in the body.
It is to clear neither how can I declare a variable of type Either
string int. I see that I can declare a Left string and a Right int
BOOST_HANA_CONSTEXPR_LAMBDA auto left_value = left("x");
BOOST_HANA_CONSTEXPR_LAMBDA auto right_value = right(1);
I have the impression that the variables are initialized only once and
can not be reassigned,or at least we can not assing a Left value to a
variable initialized with a Right value. Is this by design?
A last concern related to the applicative lift function. I suspect that
it corresponds to the Haskell return function and the more general unit
Monad function.
As there is a lift function in Haskell, this is a little bit confusing.
I have named this function make :) In Haskell, the template parameter is
a type constructor. This Monad(Applicative) type constructor should be
Either E, not Either. Is the type-constructor feature missing from your
design?
How wan I create an Either string int with a call to
auto x =lift<Either>(123);
I would expect something like
auto x = lift<Either<string>>(123);
In my prototype I have
auto x = make<expected<holder, string>>(123);
where expected<holder, string> is the Monad type constructor for
expected<T, string>.
Sorry the argument of expected and Either are in interchanged. The
string type is the Error.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk