The context here is that Haskell has a joke acme-don't package which defines a single function:
-- | Do not execute the argument.
don't :: Applicative f => f a -> f ()
don't _ = pure ()
… and I proposed changing the definition recently:
I feel like the implementation of don’t should be changed to:
don’t :: Monoid m => m don’t = mempty… mainly so that you can still use it like in the original example from the documentation (because of the Monoid instance for functions):
main = don’t $ do name <- getLine putStrLn $ “hello “ ++ name… but with the mempty definition you can also write:
main = don’t -- Just … don’tThis is not strictly more general than the existing implementation, because not all Applicatives implement Monoid. However, a lot of them do (most Applicatives of interest) and many of the ones that don’t probably should anyway. See:
Plus the Monoid-based implementation can be used in contexts that are Monoids but not Applicatives, like this:
main = putStrLn (don’t “Hello, world”). -- Prints “”
