From c821b83ac3c6f6cceeceee702b033d53aa92258c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 16 Sep 2009 14:04:54 +0000 Subject: [PATCH] Use let !y = x in .. x .. instead of seq in $! and evaluate (#2273) --- GHC/IO.hs | 7 ++----- Prelude.hs | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/GHC/IO.hs b/GHC/IO.hs index f2ccc7d..9615953 100644 --- 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 diff --git a/Prelude.hs b/Prelude.hs index 1006bdc..8ede773 100644 --- a/Prelude.hs +++ b/Prelude.hs @@ -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 -- 1.7.10.4