Skip to content

[#912] Add or, and, or1, and1, not functions for overloaded booleans

Nikolay Yakimov requested to merge lierdakil/#912-lifted-or-and into master

Description

Problem: our overloaded booleans don't support some quality of life stuff.

Solution: turned out to be a little tricky.

TL;DR:

  1. Add negation to overloaded booleans
  2. Implement negation for TransferFailurePredicate
  3. Add BooleanMonoid type class defining true and false.

We need (1) to be able to define true and false in terms of each other in (3), so that downstream could only define one of those if they choose so. We have to do (2) as a direct consequence of (1).

That being said, if we can live with requiring both true and false to be defined, we could drop (1) and (2).

Alternative design:

Since conjunction is a monoid wrt True and disjunction is a monoid wrt False, instead of defining a single class BooleanMonoid, we could define two, class BooleanTrue a where true :: a and class BooleanFalse a where false :: a. Thus, and would only need BooleanTrue constraint, and or respectively BooleanFalse.

This seemed more ad-hoc, and deriving instances for two classes instead of one is somewhat annoying, so I didn't go for it, but it's an option.

Related issue(s)

Resolves #912 (closed)

Checklist for your Merge Request

Related changes (conditional)

  • Tests (see short guidelines)

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Nikolay Yakimov

Merge request reports