Boost logo

Boost :

Subject: Re: [boost] Ternary logic programming (was: Re: [variant] Maintainer)
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-07-02 13:28:58

On 2 Jul 2015 at 8:31, Steve M. Robbins wrote:

> > > In your monad application, I have never seen operators || or && mentioned,
> > > so there seems to be no reason to adapt names "true" and "false" for the
> > > three states. You might as well call them "A", "B" or "C", or to more
> > > closely reflect your application: "value", "failure", "internal_error".
> > >
> > > Am I missing something?
> >
> > Hopefully I explained it in my reply to Charley.
> I didn't see this question addressed.

A monad has an expected and an unexpected outcome. That naturally
maps to true and false.

My mongel monads can also be empty. That implies a ternary state. No
one can disagree that the expected state ought to map to true. A
valid disagreement is whether empty or unexpected should be false or

I chose the errored/excepted state to be the indeterminate, because I
felt that null and value_type states are exactly what they are, but
an error_code and especially an exception_ptr is quite literally
unknown until you interrogate/rethrow it.

> > There are also accessor member functions on monad, so
> > empty()/has_value()/has_error()/has_exception().
> So that should be enough, then? You could write the logic in clear terms:
> if (monad.has_value()) { .. }
> else if (monad.has_error()) { ... }
> ...


if(monad==tribool::true) {}
else if(monad==tribool::false) {}
else if(monad==tribool::unknown) {}

or even, as Charley mentioned:

  case tribool::true:
  case tribool::false:

> Why even bring up "tribool" at all in this context? It seems like an
> invitation for people to make buggy / unclear code.

Maybe. It's why I've been asking here. As I mentioned, I can see a
use case for this. If you watch Charley's talk from C++ Now, I found
it compelling for its niche use case.

I'll know the practical experience in a few weeks from now as I
integrate these into AFIO and get some practice with constructing
ternary AND/OR sequences from them. If I find them problematic, I'll
remove tribool support completely.


ned Productions Limited Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at