ekmett / ersatz

A monad for interfacing with external SAT solvers
Other
62 stars 15 forks source link

strictness of default implementation of choose #53

Open jwaldmann opened 3 years ago

jwaldmann commented 3 years ago

Default implementation is

class Boolean b where
  ...
  choose f t s = (f && not s) || (t && s)

This is strict in f. It's overridden here

instance Boolean Bool where
  ...
  choose f _ False = f
  choose _ t True  = t

to match the strictness of Data.Bool.bool

If we'd replace the default with

 choose f t s = (not s && f) || (s && t)

then it would give the correct strictness for the Bool instance.

But it's more code (more function calls) so we'd override it anyway...

Unless GHC inlines definitions of not, (&&), (||) and simplifies the resulting nested case expressions. Can it do this?

Well, it's a fringe use case.