{-# LANGUAGE ExplicitForAll #-}
module Data.Massiv.Array.Mutable.Internal
( unsafeCreateArray
, unsafeCreateArray_
, unsafeCreateArrayS
) where
import Control.Scheduler
import Data.Massiv.Core.Common
unsafeCreateArrayS ::
forall r ix e a m. (Mutable r ix e, PrimMonad m)
=> Sz ix
-> (MArray (PrimState m) r ix e -> m a)
-> m (a, Array r ix e)
unsafeCreateArrayS sz action = do
marr <- unsafeNew sz
a <- action marr
arr <- unsafeFreeze Seq marr
return (a, arr)
{-# INLINE unsafeCreateArrayS #-}
unsafeCreateArray ::
forall r ix e a m b. (Mutable r ix e, PrimMonad m, MonadUnliftIO m)
=> Comp
-> Sz ix
-> (Scheduler m a -> MArray (PrimState m) r ix e -> m b)
-> m ([a], Array r ix e)
unsafeCreateArray comp sz action = do
marr <- unsafeNew sz
a <- withScheduler comp (`action` marr)
arr <- unsafeFreeze comp marr
return (a, arr)
{-# INLINE unsafeCreateArray #-}
unsafeCreateArray_ ::
forall r ix e a m b. (Mutable r ix e, PrimMonad m, MonadUnliftIO m)
=> Comp
-> Sz ix
-> (Scheduler m a -> MArray (PrimState m) r ix e -> m b)
-> m (Array r ix e)
unsafeCreateArray_ comp sz action = do
marr <- unsafeNew sz
withScheduler_ comp (`action` marr)
arr <- unsafeFreeze comp marr
return arr
{-# INLINE unsafeCreateArray_ #-}