Hi Leonidas
This is an interesting example. If I understand you correctly, what you want to do is to focus on one particular item, apply a (State) monadic computation that modifies it, replace that in the main list, as part of a larger monadic computation (also in a State monad / StateT transformer).
The first part, focusing on a sub-element, is fine. You could have an operation on a State monad that allows you to focus on a substate. But the problem is merging the result back into the main state: that would not happen automatically.
(Note for other readers: reminds me of lenses. Maybe StateT and Lens can be combined?)
It seems to me that, in this case, what you are already doing would be roughly the way to do it (if you want to use State also to modify the inner items).
Example of state transformers:
Imagine that you have an additional, distinguished Item, that you need to keep apart (apart is the keyword, not the fact that it's only one).
Then the monad you would be handling would be like:
State (ItemManager, Item)
No matter how many Items you have in the ItemManager (may be zero), you always have a distinguished Item separated.
But that means that, to manipulate this, you'd have to extract the ItemManager, modify it, put it back in the tuple, etc. So, you can also do:
StateT ItemManager (State Item)
Which means that you can modify ItemManager and Item independently, and manipulate both with:
op :: StateT ItemManager (State Item) ()
op = do
modify f -- computation that affects item manager
lift (modify g) -- computation that affects single item
...
You would then define your operations to be more flexible:
increaseCounterInItems :: StateT ItemManager m ()
So, you could also do:
op :: StateT ItemManager (State Item) ()
op = do
increaseCounterIntItems -- adds one to every Item in ItemManager
lift increaseCounter -- adds one to the single Item
...
Hope that helps
Best wishes
Ivan