<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>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.<br></div><div><br></div><div>On Mon, 21 Dec 2020, at 6:54 PM, Tom Ellis wrote:<br></div><blockquote type="cite" id="qt" style=""><div>On Mon, Dec 21, 2020 at 07:19:49PM +0100, Ben Franksen wrote:<br></div><div>> So, a simple type class Boolean with instances for Bool and<br></div><div>> functions returning Booleans should cover the majority of use cases;<br></div><div>> more instances could be added of course. Something like<br></div><div>[...]<br></div><div>> instance Boolean Bool where<br></div><div>>   (&&) = (Prelude.&&)<br></div><div>>   (||) = (Prelude.||)<br></div><div>>   not = Prelude.not<br></div><div>>   top = True<br></div><div>>   bottom = False<br></div><div>> <br></div><div>> instance Boolean b => Boolean (a->b) where<br></div><div>>   (f && g) x = f x && g x<br></div><div>>   (f || g) x = f x || g x<br></div><div>>   (not f) x = not (f x)<br></div><div>>   top = const top<br></div><div>>   bottom = const bottom<br></div><div><br></div><div>I think it's worth seeing more instances. As it is I don't understand<br></div><div>in what situations one would use these polymorphically and therefore<br></div><div>why `liftA2 (&&)`, `fmap not`, `pure True` and friends wouldn't<br></div><div>suffice.<br></div><div><br></div><div>Tom<br></div><div>_______________________________________________<br></div><div>Libraries mailing list<br></div><div><a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br></div><div><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br></div><div><br></div></blockquote><div><br></div></body></html>