Monad for Const? [英] Monad for Const?

查看:63
本文介绍了Monad for Const?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么没有Control.Applicative.Const的monad实例?遵循以下定义正确无误,还是违反了monad法律?

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?

推荐答案

它违反了左身份法:必须与f x相同,但请考虑f x = Const (x + 1).

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

这篇关于Monad for Const?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆