Monads in D
Atila Neves via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 11 10:49:11 PDT 2016
On Saturday, 11 June 2016 at 16:50:15 UTC, qznc wrote:
> On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:
>> Why? Because I could, I don't plan on using this for anything
>> serious. I think "with" is my favourite D feature right now. I
>> also wrote the Writer and State monads (not that D needs them):
>
> I also tried this. Instead of Write and State, I tried to model
> the Functor > Applicative > Monad > MonadFail type hierarchy. I
> found no way for a good "template inheritance" construct.
> Overall, I quickly forgot about it, because it looks ugly and
> seems to have no advantage.
I was thinking of doing that as well and was going to model the
hierarchy like so:
alias isFunctor = isInputRange;
enum isApplicative(alias T, U...) = isFunctor!T && is(typeof() {
... }));
enum isMonad(alias T, U...) = isApplicative!(T, U) &&
is(typeof(() { ... }));
> Thinking more conceptually, Monads should be somewhat related
> to input ranges, as both model a linear sequence.
Monads are related to input ranges because every monad is a
functor, and input ranges are functors.
Atila
More information about the Digitalmars-d
mailing list