Skip to content

Commit

Permalink
Make IOGenM and STGenM lazy in the value generated
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Oct 27, 2024
1 parent 90d92a8 commit 99073e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/System/Random/Stateful.hs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ applyIOGen :: MonadIO m => (g -> (a, g)) -> IOGenM g -> m a
applyIOGen f (IOGenM ref) = liftIO $ do
g <- readIORef ref
case f g of
(!a, !g') -> a <$ writeIORef ref g'
(a, !g') -> a <$ writeIORef ref g'
{-# INLINE applyIOGen #-}

-- | Wraps an 'STRef' that holds a pure pseudo-random number generator.
Expand Down Expand Up @@ -600,7 +600,7 @@ applySTGen :: (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen f (STGenM ref) = do
g <- readSTRef ref
case f g of
(!a, !g') -> a <$ writeSTRef ref g'
(a, !g') -> a <$ writeSTRef ref g'
{-# INLINE applySTGen #-}

-- | Runs a monadic generating action in the `ST` monad using a pure
Expand Down

0 comments on commit 99073e7

Please sign in to comment.