[commit: packages/time] master: NFData instances, contributed by Herbert Valerio Riedel <hvriedel at gmail.com> (4466857)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 23:00:34 UTC 2015


Repository : ssh://git@git.haskell.org/time

On branch  : master
Link       : http://git.haskell.org/packages/time.git/commitdiff/4466857c177c0315e8400fe7d64b930d52e12ce1

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

commit 4466857c177c0315e8400fe7d64b930d52e12ce1
Author: Ashley Yakeley <ashley at semantic.org>
Date:   Mon Sep 12 03:08:07 2011 -0700

    NFData instances, contributed by Herbert Valerio Riedel <hvriedel at gmail.com>
    
    Ignore-this: 5279778ec762aa123b8ff68f417d5353
    
    darcs-hash:20110912100807-ac6dd-182208624a89df2741cdc147aa1f6255cf35ee9d


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

4466857c177c0315e8400fe7d64b930d52e12ce1
 Data/Time/Calendar/Days.hs       | 4 ++++
 Data/Time/Clock/Scale.hs         | 8 ++++++++
 Data/Time/Clock/TAI.hs           | 4 ++++
 Data/Time/Clock/UTC.hs           | 7 +++++++
 Data/Time/LocalTime/LocalTime.hs | 7 +++++++
 Data/Time/LocalTime/TimeOfDay.hs | 4 ++++
 Data/Time/LocalTime/TimeZone.hs  | 4 ++++
 time.cabal                       | 4 ++--
 8 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/Data/Time/Calendar/Days.hs b/Data/Time/Calendar/Days.hs
index bd2be33..c09a273 100644
--- a/Data/Time/Calendar/Days.hs
+++ b/Data/Time/Calendar/Days.hs
@@ -7,6 +7,7 @@ module Data.Time.Calendar.Days
 	Day(..),addDays,diffDays
 ) where
 
+import Control.DeepSeq
 import Data.Ix
 import Data.Typeable
 #if LANGUAGE_Rank2Types
@@ -22,6 +23,9 @@ newtype Day = ModifiedJulianDay {toModifiedJulianDay :: Integer} deriving (Eq,Or
 #endif
     )
 
+instance NFData Day where
+	rnf (ModifiedJulianDay a) = rnf a
+
 instance Typeable Day where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Calendar.Days.Day") []
 
diff --git a/Data/Time/Clock/Scale.hs b/Data/Time/Clock/Scale.hs
index fb67cc5..37c3f32 100644
--- a/Data/Time/Clock/Scale.hs
+++ b/Data/Time/Clock/Scale.hs
@@ -12,6 +12,7 @@ module Data.Time.Clock.Scale
         secondsToDiffTime, picosecondsToDiffTime
 ) where
 
+import Control.DeepSeq
 import Data.Ratio ((%))
 import Data.Fixed
 import Data.Typeable
@@ -29,6 +30,10 @@ newtype UniversalTime = ModJulianDate {getModJulianDate :: Rational} deriving (E
 #endif
     )
 
+-- necessary because H98 doesn't have "cunning newtype" derivation
+instance NFData UniversalTime where
+	rnf (ModJulianDate a) = rnf a
+
 instance Typeable UniversalTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.Scale.UniversalTime") []
 
@@ -46,6 +51,9 @@ newtype DiffTime = MkDiffTime Pico deriving (Eq,Ord
 #endif
     )
 
+-- necessary because H98 doesn't have "cunning newtype" derivation
+instance NFData DiffTime -- FIXME: Data.Fixed had no NFData instances yet at time of writing
+
 instance Typeable DiffTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.Scale.DiffTime") []
 
diff --git a/Data/Time/Clock/TAI.hs b/Data/Time/Clock/TAI.hs
index 946e4ca..77c2134 100644
--- a/Data/Time/Clock/TAI.hs
+++ b/Data/Time/Clock/TAI.hs
@@ -18,6 +18,7 @@ module Data.Time.Clock.TAI
 import Data.Time.LocalTime
 import Data.Time.Calendar.Days
 import Data.Time.Clock
+import Control.DeepSeq
 import Data.Typeable
 import Data.Fixed
 #if LANGUAGE_Rank2Types
@@ -35,6 +36,9 @@ newtype AbsoluteTime = MkAbsoluteTime {unAbsoluteTime :: DiffTime} deriving (Eq,
 #endif
     )
 
+instance NFData AbsoluteTime where
+	rnf (MkAbsoluteTime a) = rnf a
+
 instance Typeable AbsoluteTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.TAI.AbsoluteTime") []
 
diff --git a/Data/Time/Clock/UTC.hs b/Data/Time/Clock/UTC.hs
index 1153bf8..e172b15 100644
--- a/Data/Time/Clock/UTC.hs
+++ b/Data/Time/Clock/UTC.hs
@@ -15,6 +15,7 @@ module Data.Time.Clock.UTC
 	UTCTime(..),NominalDiffTime
 ) where
 
+import Control.DeepSeq
 import Data.Time.Calendar.Days
 import Data.Time.Clock.Scale
 import Data.Fixed
@@ -40,6 +41,9 @@ data UTCTime = UTCTime {
 #endif
 #endif
 
+instance NFData UTCTime where
+	rnf (UTCTime d t) = d `deepseq` t `deepseq` ()
+
 instance Typeable UTCTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.UTC.UTCTime") []
 
@@ -67,6 +71,9 @@ newtype NominalDiffTime = MkNominalDiffTime Pico deriving (Eq,Ord
 #endif
     )
 
+-- necessary because H98 doesn't have "cunning newtype" derivation
+instance NFData NominalDiffTime -- FIXME: Data.Fixed had no NFData instances yet at time of writing
+
 instance Typeable NominalDiffTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.UTC.NominalDiffTime") []
 
diff --git a/Data/Time/LocalTime/LocalTime.hs b/Data/Time/LocalTime/LocalTime.hs
index 0a79728..feb0341 100644
--- a/Data/Time/LocalTime/LocalTime.hs
+++ b/Data/Time/LocalTime/LocalTime.hs
@@ -17,6 +17,7 @@ import Data.Time.LocalTime.TimeOfDay
 import Data.Time.LocalTime.TimeZone
 import Data.Time.Calendar
 import Data.Time.Clock
+import Control.DeepSeq
 import Data.Typeable
 #if LANGUAGE_Rank2Types
 import Data.Data
@@ -39,6 +40,9 @@ data LocalTime = LocalTime {
 #endif
     )
 
+instance NFData LocalTime where
+	rnf (LocalTime d t) = d `deepseq` t `deepseq` ()
+
 instance Typeable LocalTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.LocalTime.LocalTime.LocalTime") []
 
@@ -79,6 +83,9 @@ data ZonedTime = ZonedTime {
 #endif
 #endif
 
+instance NFData ZonedTime where
+	rnf (ZonedTime lt z) = lt `deepseq` z `deepseq` ()
+
 instance Typeable ZonedTime where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.LocalTime.LocalTime.ZonedTime") []
 
diff --git a/Data/Time/LocalTime/TimeOfDay.hs b/Data/Time/LocalTime/TimeOfDay.hs
index 37b2079..ed0dbed 100644
--- a/Data/Time/LocalTime/TimeOfDay.hs
+++ b/Data/Time/LocalTime/TimeOfDay.hs
@@ -13,6 +13,7 @@ module Data.Time.LocalTime.TimeOfDay
 import Data.Time.LocalTime.TimeZone
 import Data.Time.Calendar.Private
 import Data.Time.Clock
+import Control.DeepSeq
 import Data.Typeable
 import Data.Fixed
 #if LANGUAGE_Rank2Types
@@ -38,6 +39,9 @@ data TimeOfDay = TimeOfDay {
 #endif
     )
 
+instance NFData TimeOfDay where
+	rnf (TimeOfDay h m s) = h `deepseq` m `deepseq` s `seq` () -- FIXME: Data.Fixed had no NFData instances yet at time of writing
+
 instance Typeable TimeOfDay where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.LocalTime.TimeOfDay.TimeOfDay") []
 
diff --git a/Data/Time/LocalTime/TimeZone.hs b/Data/Time/LocalTime/TimeZone.hs
index 35ffaab..16b2e52 100644
--- a/Data/Time/LocalTime/TimeZone.hs
+++ b/Data/Time/LocalTime/TimeZone.hs
@@ -19,6 +19,7 @@ import Data.Time.Clock.POSIX
 
 import Foreign
 import Foreign.C
+import Control.DeepSeq
 import Data.Typeable
 #if LANGUAGE_Rank2Types
 import Data.Data
@@ -40,6 +41,9 @@ data TimeZone = TimeZone {
 #endif
     )
 
+instance NFData TimeZone where
+	rnf (TimeZone m so n) = m `deepseq` so `deepseq` n `deepseq` ()
+
 instance Typeable TimeZone where
 	typeOf _ = mkTyConApp (mkTyCon "Data.Time.LocalTime.TimeZone.TimeZone") []
 
diff --git a/time.cabal b/time.cabal
index 21bf3e4..c8f0f0f 100644
--- a/time.cabal
+++ b/time.cabal
@@ -1,5 +1,5 @@
 name:           time
-version:        1.3
+version:        1.4
 stability:      stable
 license:        BSD3
 license-file:   LICENSE
@@ -35,7 +35,7 @@ extra-tmp-files:
 
 library
 {
-    build-depends: base == 4.*, old-locale
+    build-depends: base == 4.*, deepseq >= 1.1 && < 1.2, old-locale
     ghc-options: -Wall
     if impl(ghc)
         extensions: Rank2Types DeriveDataTypeable StandaloneDeriving



More information about the ghc-commits mailing list