给定一个 Writer
monad Action ,我想通过将函数映射到 monad Action 中的写入数据来修改它。
就像是:
retell :: (w -> w') -> Writer w a -> Writer w' a
库中是否已经存在这样的功能?如果不是,如何定义?
最佳答案
retell f = Writer . second f $ runWriter
还有一个
mapWriter
库提供的功能。所以你可以这样做:retell = mapWriter . second
second
函数在 Control.Arrow
,但您可以自己定义一个不太通用的版本,如下所示:second f (a, b) = (a, f b)
关于haskell - 更改 Writer monad 中的写入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10641658/