Add MutInt#
One can use PrimVar Int from primitive, which is essentially a ByteArray# fitting one Int. That representation however has additional heap object and need to follow a pointer on access. MutInt# would be mutable bits directly inside the object.
More generally, we could want to have a primitive for unboxed representations, say Ref#, generalising MutInt# and possible MutDouble#, MutWord# etc; but I think MutInt# is easier to implement, and enough for my current needs.
Also MutInt# can support operations like
casMutInt# :: MutInt# d -> Int# -> Int# -> State# d -> (# State# d, Int# #)
The more general Ref# could also have specialised versions like
casRefInt# :: Ref# d Int# -> Int# -> Int# -> State# d -> (# State# d, Int# #)
casRefInt8# :: Ref# d Int8# -> Int8# -> Int8# -> State# d -> (# State# d, Int8# #)
... -- like `casIntArray#` etc friends
but again, I think MutInt# is hopefully easier to implement; and if Ref# is later done too, one could change type MutInt# = Ref# Int#.
Edited by Oleg Grenrus