I want a function that takes in a list and indexes out all the contents: indexed :: [a] -> [(Int, a)]
. Or the returned value can be whatever Monad as long as it contains indexed values of the original list.
I thought that I would need StateT to temporary remember and inclement index numbers while processing each element, but I'm not familiar with Monad transformer thingy and I need some help write the function.
I believe it will look similar to this (this is sure not working):
indexed ns = do
n <- ns
i <- get
put (i + 1)
return (i, n)
How would you write it?