Repository : ssh://darcs.haskell.org//srv/darcs/packages/deepseq

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/24506eea886d94e8d3cc6b86e47f18b3f9d573c2

>---------------------------------------------------------------

commit 24506eea886d94e8d3cc6b86e47f18b3f9d573c2
Author: Simon Marlow <[email protected]>
Date:   Tue Jul 19 09:39:31 2011 +0100

    Add ($!!) and force, as per #5323

>---------------------------------------------------------------

 Control/DeepSeq.hs |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/Control/DeepSeq.hs b/Control/DeepSeq.hs
index 9d72ae2..d59aebb 100644
--- a/Control/DeepSeq.hs
+++ b/Control/DeepSeq.hs
@@ -42,7 +42,7 @@
 -- the wrong threads).
 --
 module Control.DeepSeq (
-     deepseq,
+     deepseq, ($!!), force,
      NFData(..),
   ) where
 
@@ -57,6 +57,8 @@ import Data.IntSet
 import Data.Tree
 import Data.Array
 
+infixr 0 $!!
+
 -- | 'deepseq': fully evaluates the first argument, before returning the
 -- second.
 --
@@ -79,6 +81,23 @@ import Data.Array
 deepseq :: NFData a => a -> b -> b
 deepseq a b = rnf a `seq` b
 
+-- | the deep analogue of '$!'.  In the expression @f $!! x@, @x@ is
+-- fully evaluated before the function @f@ is applied to it.
+($!!) :: (NFData a) => (a -> b) -> a -> b
+f $!! x = x `deepseq` f x
+
+-- | a variant of 'deepseq' that is useful in some circumstances:
+--
+-- > force x = x `deepseq` x
+--
+-- @force x@ fully evaluates @x@, and then returns it.  Note that
+-- @force x@ only performs evaluation when the value of @force x@
+-- itself is demanded, so essentially it turns shallow evaluation into
+-- deep evaluation.
+
+force :: (NFData a) => a -> a
+force x = x `deepseq` x
+
 -- | A class of types that can be fully evaluated.
 class NFData a where
     -- | rnf should reduce its argument to normal form (that is, fully



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to