Looking here http://hackage.haskell.org/package/vector-0.12.0.3/docs/Data-Vector-Mutable.html One can see that the type of read is:
read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
Since read operation does not modify the vector, my main question is why is it not:
read :: PrimMonad m => MVector (PrimState m) a -> Int -> a
The length of a mutable vector is also doing something immutable on a vector, and its type is MVector s a -> Int which looks normal. It is not PrimMonad m => MVector (PrimState m) a -> m Int.
So why was this difference of design choice made between read and length since they are both immutable operations on a vector?
Now that I think about it, could it be somehow that the cell returned by read is a reference to the cell inside the vector and not a copy of its data? If so how can I nicely and cheaply get immutable access to the n-th element in a mutable vector? I'm learning haskell and not too sure about details.
Thanks,