Commits

Bryan O'Sullivan committed 0d04a99

Add whnfIO.

  • Participants
  • Parent commits 9781559

Comments (0)

Files changed (3)

File Criterion.hs

     , Benchmark
     , Pure
     , nf
+    , whnf
     , nfIO
-    , whnf
+    , whnfIO
     , bench
     , bgroup
     , runBenchmark

File Criterion/Main.hs

     , bench
     , bgroup
     , nf
+    , whnf
     , nfIO
-    , whnf
+    , whnfIO
     -- * Running benchmarks
     , defaultMain
     , defaultMainWith

File Criterion/Types.hs

     , whnf
     , nf
     , nfIO
+    , whnfIO
     , bench
     , bgroup
     , benchNames
 -- This is particularly useful for forcing a lazy IO action to be
 -- completely performed.
 nfIO :: NFData a => IO a -> IO ()
-nfIO a = a >>= \k -> return $! rnf k
+nfIO a = evaluate . rnf =<< a
 {-# INLINE nfIO #-}
 
+-- | Perform an action, then evaluate its result to weak head normal
+-- form (WHNF).  This is useful for forcing an IO action whose result
+-- is an expression to be evaluated down to a more useful value.
+whnfIO :: NFData a => IO a -> IO ()
+whnfIO a = a >>= evaluate >> return ()
+{-# INLINE whnfIO #-}
+
 instance Benchmarkable Pure where
     run p@(WHNF _ _) = go p
       where