Which one makes more sense for you and why?

whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()


whenJust :: (Applicative f, Monoid m) => Maybe a -> (a -> f m) -> f m


whenJust :: Monoid m => Maybe a -> (a -> m) -> m


That last one doesn't work for all Monads, for one it doesn't work with Either, but I still managed to find people using it.

Although I suppose someone could argue that instance Monoid m => Monoid (Either m) would be lawful, but it just adds headache without much benefit to the cause.

There already are too many lawful instances in Haskell that shouldn't really exist. instance Foldable (a,) is one of those. Or maybe Foldable itself is just bad design, I don't know.

Sign in to participate in the conversation
Functional Café

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!