Use let !y = x in .. x .. instead of seq in $! and evaluate (#2273)
authorSimon Marlow <marlowsd@gmail.com>
Wed, 16 Sep 2009 14:04:54 +0000 (14:04 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 16 Sep 2009 14:04:54 +0000 (14:04 +0000)
GHC/IO.hs
Prelude.hs

index f2ccc7d..9615953 100644 (file)
--- a/GHC/IO.hs
+++ b/GHC/IO.hs
@@ -1,5 +1,5 @@
 {-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# OPTIONS_GHC -XNoImplicitPrelude -funbox-strict-fields #-}
+{-# OPTIONS_GHC -XNoImplicitPrelude -funbox-strict-fields -XBangPatterns #-}
 {-# OPTIONS_HADDOCK hide #-}
 -----------------------------------------------------------------------------
 -- |
@@ -336,7 +336,4 @@ a `finally` sequel =
 -- >   evaluate x = (return $! x) >>= return
 --
 evaluate :: a -> IO a
-evaluate a = IO $ \s -> case a `seq` () of () -> (# s, a #)
-        -- NB. can't write
-        --      a `seq` (# s, a #)
-        -- because we can't have an unboxed tuple as a function argument
+evaluate a = IO $ \s -> let !va = a in (# s, va #) -- NB. see #2273
index 1006bdc..8ede773 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -XNoImplicitPrelude #-}
+{-# OPTIONS_GHC -XNoImplicitPrelude -XBangPatterns #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Prelude
@@ -172,12 +172,16 @@ import Hugs.Prelude
 
 #ifndef __HUGS__
 infixr 0 $!
+#endif
 
 -- -----------------------------------------------------------------------------
 -- Miscellaneous functions
 
 -- | Strict (call-by-value) application, defined in terms of 'seq'.
 ($!)    :: (a -> b) -> a -> b
+#ifdef __GLASGOW_HASKELL__
+f $! x  = let !vx = x in f vx  -- see #2273
+#elif !defined(__HUGS__)
 f $! x  = x `seq` f x
 #endif