guard has an Applicative constraint because you do not need to perform monadic operations on it to define a function.
This definition (copied from Source hacks ):
guard :: (Alternative f) => Bool -> f () guard True = pure () guard False = empty
If he indicated MonadPlus instead of Alternative , he would not get anything. MonadPlus is a subclass of Alternative , so all MonadPlus instances can use guard , but not all Alternatives can use it.
(Although there would be very few Alternatives exceptions - both cases mentioned here have an instance of MonadPlus , although they do not satisfy the left-distribution rule.)
In general, it is best to adhere to the minimum restrictions necessary to write a function, even if the intended use is more specific. Thus, there is nothing excluded, which should not be, and no complaints from people whose types can work for him, but are not monads.
By the way, Google Search results do not correctly display the MonadPlus restriction, but if you click the link, it will be correct.
source share