Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monad for Const?

Tags:

haskell

monads

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?

like image 680
Landei Avatar asked Jul 17 '12 20:07

Landei


1 Answers

It violates the left identity law: return x >>= f must be the same as f x, but consider f x = Const (x + 1).

like image 128
ehird Avatar answered Dec 02 '22 07:12

ehird