{-# LANGUAGE BangPatterns #-} module Control.Foldl.Util.MVector where import Data.Vector.Generic.Mutable import Control.Monad.ST {-# INLINE writeListInReverseOrderStartingFrom #-} writeListInReverseOrderStartingFrom :: MVector v a => v s a -> Int -> [a] -> ST s () writeListInReverseOrderStartingFrom :: v s a -> Int -> [a] -> ST s () writeListInReverseOrderStartingFrom v s a v = let loop :: Int -> [a] -> ST s () loop !Int index [a] list = case [a] list of a h : [a] t -> do v (PrimState (ST s)) a -> Int -> a -> ST s () forall (m :: * -> *) (v :: * -> * -> *) a. (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () unsafeWrite v s a v (PrimState (ST s)) a v Int index a h Int -> [a] -> ST s () loop (Int -> Int forall a. Enum a => a -> a pred Int index) [a] t [a] _ -> () -> ST s () forall (m :: * -> *) a. Monad m => a -> m a return () in Int -> [a] -> ST s () loop