"guard" doesn't need MonadPlus, just Alternative.
commit2d17b67bac1148a537e25cf48566a35ae3f7991a
authorstartling <tdixon51793@gmail.com>
dateThu 13 Dec 2012, 20:38 (14 years ago)
parent314bcf1
lib/Prelude/Applicative.idr+3
@@ -14,3 +14,6 @@ class Functor f => Applicative (f : Type -> Type) where
1414class Applicative f => Alternative (f : Type -> Type) where
1515 empty : f a
1616 (<|>) : f a -> f a -> f a
17+
18+guard : Alternative f => Bool -> f ()
19+guard a = if a then pure () else empty
lib/Prelude/Monad.idr−4
@@ -18,10 +18,6 @@ class Monad m => MonadPlus (m : Type -> Type) where
1818 mplus : m a -> m a -> m a
1919 mzero : m a
2020
21−guard : MonadPlus m => Bool -> m ()
22−guard True = return ()
23−guard False = mzero
24−
2521when : Monad m => Bool -> m () -> m ()
2622when True f = f
2723when False _ = return ()