I've wanted it when writing DSLs. For example, when doing SQL query generation, if you have some Expr a type to represent database expressions of type 'a', it'd be nice to be able to have && "just work" on them, much like how we can add a Num (Expr a) instance. If other functions were written in terms of Bool, these are trivially useful on Expr now, but without that they have to be re-implemented.

On Mon, 21 Dec 2020, at 6:54 PM, Tom Ellis wrote:
On Mon, Dec 21, 2020 at 07:19:49PM +0100, Ben Franksen wrote:
> So, a simple type class Boolean with instances for Bool and
> functions returning Booleans should cover the majority of use cases;
> more instances could be added of course. Something like
[...]
> instance Boolean Bool where
>   (&&) = (Prelude.&&)
>   (||) = (Prelude.||)
>   not = Prelude.not
>   top = True
>   bottom = False

> instance Boolean b => Boolean (a->b) where
>   (f && g) x = f x && g x
>   (f || g) x = f x || g x
>   (not f) x = not (f x)
>   top = const top
>   bottom = const bottom

I think it's worth seeing more instances. As it is I don't understand
in what situations one would use these polymorphically and therefore
why `liftA2 (&&)`, `fmap not`, `pure True` and friends wouldn't
suffice.

Tom
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries