File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,16 @@ module Data.Array.ST
1313 , pushAllSTArray
1414 , spliceSTArray
1515 , freeze , thaw
16+ , unsafeFreeze
1617 , toAssocArray
1718 ) where
1819
20+ import Prelude
1921import Control.Monad.Eff (Eff )
2022import Control.Monad.ST (ST )
2123
2224import Data.Maybe (Maybe (..))
25+ import Unsafe.Coerce (unsafeCoerce )
2326
2427-- | A reference to a mutable array.
2528-- |
@@ -33,6 +36,8 @@ foreign import data STArray :: * -> * -> *
3336-- | An element and its index.
3437type Assoc a = { value :: a , index :: Int }
3538
39+ -- | **DEPRECATED**: Use `unsafeFreeze` together with `runST` instead.
40+ -- |
3641-- | Freeze a mutable array, creating an immutable array. Use this function as you would use
3742-- | `runST` to freeze a mutable reference.
3843-- |
@@ -42,6 +47,11 @@ foreign import runSTArray
4247 . (forall h . Eff (st :: ST h | r ) (STArray h a ))
4348 -> Eff r (Array a )
4449
50+ -- | O(1). Convert a mutable array to an immutable array, without copying. The mutable
51+ -- | array must not be mutated afterwards.
52+ unsafeFreeze :: forall a r h . STArray h a -> Eff (st :: ST h | r ) (Array a )
53+ unsafeFreeze = pure <<< (unsafeCoerce :: STArray h a -> Array a )
54+
4555-- | Create an empty mutable array.
4656foreign import emptySTArray :: forall a h r . Eff (st :: ST h | r ) (STArray h a )
4757
You can’t perform that action at this time.
0 commit comments