
10 Apr
2019
10 Apr
'19
2:10 p.m.
On 10-04-19 14:04, Mario Blažević wrote:
On 2019-04-10 11:36 a.m., James Ashwell wrote:
This would mimic the behaviour of Control.Monad.when for monoids rather than applicatives.
mwhen :: Monoid m => Bool -> m -> m
mwhen b a | b = a | otherwise = mempty
Or shorter
mwhen = bool (const mempty) id
I'd rather construct the right-hand side than memorize the left, so -1 from me. Exactly, monoids usually don't operate on their own context as Monad/Applicatives do. It is better to see them as pure values dependent on `Bool`, for which Data.Bool.bool is a perfect function. Also the rhs is clearer and easier to remember.
A -1 from me. -- -- Rubén -- pgp: 4EE9 28F7 932E F4AD