type class Boolean

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Mon Dec 21 18:54:40 UTC 2020


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


More information about the Libraries mailing list