Boost logo

Boost :

Subject: Re: [boost] [mpl] multiset
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-03-16 17:59:04


Louis Dionne <ldionne.2 <at> gmail.com> writes:

>
> Eric Niebler <eniebler <at> boost.org> writes:
>
> [...]
>
> > > Lazy is a Monad, which allows chaining lazy computations as shown
> > > in [1]. However, Lazy is not integrated with eval_if right now, which
> > > makes it pretty much useless. The reason why it is not integrated is
> > > because I think it can also be made a Comonad, and I wanted to see how
> > > lazy branching might be generalizable to arbitrary Comonads.
> > > I haven't had the time to explore this further for now though.
> >
> > FWIW, I think this is important.
>
> I think so too, and it is on my (super long) todo list. Unfortunately,
> I'm only a man not an army. I'll try to have this in time for the
> formal review, which is aimed for April.

I'm now fairly sure laziness can be expressed as a Comonad.
I explained it on my (new!) blog [1]. In summary, it would
be correct to have

    eval_if :: Comonad w => Bool -> w a -> w a -> a

In other words, if_(cond, then, else) would take a Boolean condition,
a then branch which is actually an arbitrary Comonad and an else branch
which also is an arbitrary Comonad. It would then call `extract` on the
Comonad that has been selected by the condition. One instance of this
would be with the Lazy Comonad, which would give rise to the well-known
eval_if since `extract`ing a Lazy value is just evaluating it:

    eval_if :: Bool -> Lazy a -> Lazy a -> a

Whether it's useful for something else than lazy computations
is still unclear to me, but it's worth exploring.

Louis

[1]: http://ldionne.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk