I have an array and an array index in a state monad. I can read idx using use
and modify it using +=
and other similar modifiers:
{-# Language TemplateHaskell #-}
import Control.Lens
import Control.Lens.TH
import Control.Monad.State
import Data.Array
data M = M { _arr :: Array Int Int, _idx :: Int }
$(makeLenses ''M)
foo x = do
idx += x
ii <- use idx
return ii
Now I want to combine arr
and idx
to form a lens to arr[idx]
:
combo arr idx = undefined
bar x = do
combo arr idx += x
ii <- combo arr idx
return ii
How can I do this? Will code be different for Data.Sequence
?