Monad with no wrapped value?

后端 未结 4 955
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 06:02

Most of the monad explanations use examples where the monad wraps a value. E.g. Maybe a, where the a type variable is what\'s wrapped. But I\'m won

4条回答
  •  长情又很酷
    2020-12-30 06:47

    Well there is

    data Useless a = Useless
    instance Monad Useless where
      return = const Useless
      Useless >>= f = Useless
    

    but as I indicated, that isn't usefull.

    What you want is the Writer monad, which wraps up a monoid as a monad so you can use do notation.

提交回复
热议问题