ersatz
ersatz copied to clipboard
strictness of default implementation of choose
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.