{-# 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 :: forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int -> [a] -> ST s () writeListInReverseOrderStartingFrom v s a v = let loop :: Int -> [a] -> m () loop !Int index [a] list = case [a] list of a h : [a] t -> do v (PrimState m) a -> Int -> a -> m () forall (m :: * -> *) (v :: * -> * -> *) a. (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () unsafeWrite v s a v (PrimState m) a v Int index a h Int -> [a] -> m () loop (Int -> Int forall a. Enum a => a -> a pred Int index) [a] t [a] _ -> () -> m () forall a. a -> m a forall (m :: * -> *) a. Monad m => a -> m a return () in Int -> [a] -> ST s () forall {m :: * -> *}. (PrimState m ~ s, PrimMonad m) => Int -> [a] -> m () loop