Why is there no monad instance for Control.Applicative.Const
? Is following definition correct, or violates it the monad laws?
instance Monoid a => Monad (Const a) where
return _ = Const mempty
(Const x) >>= _ = Const x
And can you think of any useful application?
It violates the left identity law: return x >>= f
must be the same as f x
, but consider f x = Const (x + 1)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With