safe-freeze-0.2: Support for safely freezing multiple arrays in the ST monad.

MaintainerReiner Pope <>
Safe HaskellSafe-Infered



Proof-of-concept support for using vector's MVectors in the new ST monad. Reexports only a minimal API from Data.Vector.Generic.Mutable, with all ST operations done in the new ST (indexed) monad.

Notable differences in API:

  • the former unsafeFreeze is in fact safe, and is now named freeze.

Example demonstration of using the new ST monad:

foo :: forall v. Vector v Int => (v Int, v Int)
foo = runST go where
  go :: forall s. ST (Normal s) (Freeze s) (v Int, v Int)
  go = new 5 >>>= a1 ->
       new 6 >>>= a2 ->
       write a1 0 3 >>>= () ->
       write a2 1 2 >>>= () ->
       freeze a1 >>>= v1 ->
       freeze a2 >>>= v2 ->
       return (v1,v2)


new :: (MVector v a, MonadST st) => Int -> STNormal st s (v s a)Source

read :: (MVector v a, MonadST st) => v s a -> Int -> STRead st s aSource

write :: (MVector v a, MonadST st) => v s a -> Int -> a -> STNormal st s ()Source

copy :: (MVector v a, MonadST st) => v s a -> v s a -> STNormal st s ()Source

freeze :: (Vector v a, MonadST st) => Mutable v s a -> STFreeze st s (v a)Source