[add Time and Complex standard haskell 98 libraries
John Meacham <john@repetae.net>**20060308014531] hunk ./data/primitives.txt 38
+# not really right, need to find out actual minimum/maximum somehow
+Foreign.C.Types.CTime, time_t, float, 0xffffffffff, 0
+
hunk ./lib/Complex.hs 15
-data  (RealFloat a)     => Complex a = !a :+ !a  deriving (Eq,Read,Show)
+-- the standard says this should have a RealFloat constraint, but that is silly.
+data  Complex a = !a :+ !a  deriving (Eq,Read,Show)
hunk ./lib/Complex.hs 37
-     (sqrt ((scaleFloat mk x)^2 + (scaleFloat mk y)^2))
+     (sqrt ((scaleFloat mk x)^(2::Int) + (scaleFloat mk y)^(2::Int)))
hunk ./lib/Complex.hs 52
-    signum 0 =  0
+    signum (0 :+ 0) =  0
hunk ./lib/Complex.hs 55
+    fromInt n =  fromInt n :+ 0
hunk ./lib/Complex.hs 63
-             fromRational a =  fromRational a :+ 0
+    fromRational a =  fromRational a :+ 0
hunk ./lib/Complex.hs 71
-    sqrt 0         =  0
+    sqrt (0 :+ 0)  =  0
hunk ./lib/Time.hs 17
-import Ix(Ix)
+import Ix
+import Locale
+import System.IO.Unsafe
+import Foreign.Ptr
+import Char
+import Foreign.C.Types
hunk ./lib/Time.hs 24
-data ClockTime = ClockTime Int -- Implementation-dependent
---instance Ord  ClockTime where ...
---instance Eq   ClockTime where ...
+data ClockTime = TOD Integer Integer -- Implementation-dependent
+    deriving(Eq,Ord)
+
+-- When a ClockTime is shown, it is converted to a CalendarTime in the current
+-- timezone and then printed.  FIXME: This is arguably wrong, since we can't
+-- get the current timezone without being in the IO monad.
+
+instance Show ClockTime where
+    showsPrec _ t = showString (calendarTimeToString
+	  			 (unsafePerformIO (toCalendarTime t)))
hunk ./lib/Time.hs 38
-           deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)
+           deriving (Eq, Ord, Enum, Bounded, Read, Show)
+
+instance Ix Month where
+    range (x,y) = enumFromTo x y
+    index (x,y) i
+        | y < x || i < x || i > y = error "Time.Month.Ix: index out of range"
+        | otherwise = fromEnum i - fromEnum x
+    inRange (x,y) i = y >= x && (not $ i < x || i > y)
+    rangeSize (x,y)
+        | y < x = 0
+        | otherwise = fromEnum y - fromEnum x
+
+
hunk ./lib/Time.hs 54
-           deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)
+           deriving (Eq, Ord, Enum, Bounded, Read, Show)
+
+instance Ix Day where
+    range (x,y) = enumFromTo x y
+    index (x,y) i
+        | y < x || i < x || i > y = error "Time.Day.Ix: index out of range"
+        | otherwise = fromEnum i - fromEnum x
+    inRange (x,y) i = y >= x && (not $ i < x || i > y)
+    rangeSize (x,y)
+        | y < x = 0
+        | otherwise = fromEnum y - fromEnum x
hunk ./lib/Time.hs 86
+getClockTime = do
+    secs <- c_time nullPtr -- can't fail, according to POSIX
+    return (TOD (ctimeToInteger secs) 0)
+
+foreign import primitive "integralCast" ctimeToInteger :: CTime -> Integer
+   -- -----------------------------------------------------------------------------
+-- | converts an internal clock time to a local time, modified by the
+-- timezone and daylight savings time settings in force at the time
+-- of conversion.  Because of this dependence on the local environment,
+-- 'toCalendarTime' is in the 'IO' monad.
+
+toCalendarTime :: ClockTime -> IO CalendarTime
+toCalendarTime =  toCalTime False
+
+-- | converts an internal clock time into a 'CalendarTime' in standard
+-- UTC format.
+
+toUTCTime :: ClockTime -> CalendarTime
+toUTCTime      =  unsafePerformIO . toCalTime True
hunk ./lib/Time.hs 106
-addToClockTime       :: TimeDiff  -> ClockTime -> ClockTime
-diffClockTimes       :: ClockTime -> ClockTime -> TimeDiff
+toCalTime :: Bool -> ClockTime -> IO CalendarTime
+toCalTime = error "toCalTime"
hunk ./lib/Time.hs 109
-toCalendarTime       :: ClockTime    -> IO CalendarTime
-toUTCTime            :: ClockTime    -> CalendarTime
hunk ./lib/Time.hs 110
-calendarTimeToString :: CalendarTime -> String
-formatCalendarTime   :: TimeLocale -> String -> CalendarTime -> String
+toClockTime = error "toClockTime"
hunk ./lib/Time.hs 115
+-- -----------------------------------------------------------------------------
+-- | @'addToClockTime' d t@ adds a time difference @d@ and a
+-- clock time @t@ to yield a new clock time.  The difference @d@
+-- may be either positive or negative.
+
+addToClockTime  :: TimeDiff  -> ClockTime -> ClockTime
+addToClockTime (TimeDiff year mon day hour min sec psec)
+	       (TOD c_sec c_psec) =
+	let
+	  sec_diff = toInteger sec +
+                     60 * toInteger min +
+                     3600 * toInteger hour +
+                     24 * 3600 * toInteger day
+	  cal      = toUTCTime (TOD (c_sec + sec_diff) (c_psec + psec))
+                                                       -- FIXME! ^^^^
+          new_mon  = fromEnum (ctMonth cal) + r_mon
+	  month' = fst tmp
+	  yr_diff = snd tmp
+          tmp
+	    | new_mon < 0  = (toEnum (12 + new_mon), (-1))
+	    | new_mon > 11 = (toEnum (new_mon `mod` 12), 1)
+	    | otherwise    = (toEnum new_mon, 0)
+
+	  (r_yr, r_mon) = mon `quotRem` 12
+
+          year' = ctYear cal + year + r_yr + yr_diff
+	in
+	toClockTime cal{ctMonth=month', ctYear=year'}
+
+-- | @'diffClockTimes' t1 t2@ returns the difference between two clock
+-- times @t1@ and @t2@ as a 'TimeDiff'.
+
+diffClockTimes  :: ClockTime -> ClockTime -> TimeDiff
+-- diffClockTimes is meant to be the dual to `addToClockTime'.
+-- If you want to have the TimeDiff properly splitted, use
+-- `normalizeTimeDiff' on this function's result
+--
+-- CAVEAT: see comment of normalizeTimeDiff
+diffClockTimes (TOD sa pa) (TOD sb pb) =
+    noTimeDiff{ tdSec     = fromIntegral (sa - sb)
+                -- FIXME: can handle just 68 years...
+              , tdPicosec = pa - pb
+              }
+
+noTimeDiff :: TimeDiff
+noTimeDiff = TimeDiff 0 0 0 0 0 0 0
+
+
hunk ./lib/Time.hs 229
+
+foreign import ccall unsafe "time.h time" c_time :: Ptr CTime -> IO CTime
+
hunk ./lib/base.cabal 7
---                 Complex,
+                 Complex,
hunk ./lib/base.cabal 21
---                 Foreign.C.OldString,
hunk ./lib/base.cabal 56
---                 Test.QuickCheck.Utils,
---                 Test.QuickCheck.Poly,
---                 Test.QuickCheck.Batch,
---                 Test.QuickCheck,
---                 Text.Show.Functions,
---                 Time,
---                 Typeable
+                 Time,
+                 Text.Show.Functions