Monad instance for pairs

后端 未结 2 2079
傲寒
傲寒 2021-01-23 20:55

This question shows an instance definition for (,) a b, where a is an instance of Monoid.

However, I don\'t know how to write sim

2条回答
  •  感动是毒
    2021-01-23 21:53

    You cannot. It's crucial for Monad to be polymorphic in its parameter, so if a particular monadish thing only makes sense for monoids, it's not a monad.

    For example, return :: Monad m => a -> m a. There's no way you can add an extra constraint to the signature of return.

提交回复
热议问题