fullmoon
@fullmoon

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’t

This 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 “”

You must log in to comment.

in reply to @fullmoon's post:

yeah, coming from PureScript, it's so funny to see that everywhere, especially since I use do as a way of avoiding $ sometimes!

on the other hand, when I finally tried implementing a Haskell-lite grammar in Happy, I saw why that decision was made in the first place (it was Easy)