Lan*_*dei 9 monads haskell
为什么没有monad实例Control.Applicative.Const?以下定义是正确的,还是违反了monad法则?
Control.Applicative.Const
instance Monoid a => Monad (Const a) where return _ = Const mempty (Const x) >>= _ = Const x
你能想到任何有用的应用吗?
ehi*_*ird 19
它违反了左侧身份法:return x >>= f必须与之相同f x,但要考虑f x = Const (x + 1).
return x >>= f
f x
f x = Const (x + 1)
归档时间:
13 年,7 月 前
查看次数:
888 次
最近记录: