Haskell - 将函数放在pair上

时间:2016-12-07 20:18:25

标签: haskell

我有一个State monad:

type S = (M.Map String Integer, [String])

现在,我有一个功能:

rTD :: [String] -> ReaderT Env (StateT S (ErrorT String IO)) 
rTD (s, _) <- get
-- (1) how to here use put function to modify one element of pair my Store ?

(1)这里如何使用put函数修改我的Store对中的一个元素?
提前谢谢。

1 个答案:

答案 0 :(得分:2)

一般情况:

rTD xs = do
    (m, ys) <- get
    let m' = ...
    let ys' = ...
    put (m', ys')

获取/修改案例:

rTD xs = do
    m <- gets fst
    let m' = ...
    modify (\s -> (m', snd s))

带镜头:

rTD xs = do
    _1 %= Map.insert "key" 777
    _2 %= ("foo":)