[commit: packages/time] master: Ix instance for Day. This is useful for e.g. storing daily tabulated data in arrays. (b94d3b7)

git at git.haskell.org git at git.haskell.org
Sun Dec 20 07:52:12 UTC 2015


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

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

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

commit b94d3b7c106b06acd57822dee8bf464022c3e53c
Author: Bjorn Buckwalter <bjorn.buckwalter at gmail.com>
Date:   Sat Nov 29 18:22:54 2008 -0800

    Ix instance for Day. This is useful for e.g. storing daily tabulated data in arrays.
    
    darcs-hash:20081130022254-03283-3e7adc8ff05bff3fb416856f6a1e58697a073cf6


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

b94d3b7c106b06acd57822dee8bf464022c3e53c
 Data/Time/Calendar/Days.hs | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Data/Time/Calendar/Days.hs b/Data/Time/Calendar/Days.hs
index 9d91db0..2e62400 100644
--- a/Data/Time/Calendar/Days.hs
+++ b/Data/Time/Calendar/Days.hs
@@ -5,6 +5,8 @@ module Data.Time.Calendar.Days
 	Day(..),addDays,diffDays
 ) where
 
+import Data.Ix
+
 -- | The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.
 newtype Day = ModifiedJulianDay {toModifiedJulianDay :: Integer} deriving (Eq,Ord)
 
@@ -19,6 +21,13 @@ instance Enum Day where
 	enumFromTo (ModifiedJulianDay a) (ModifiedJulianDay b) = fmap ModifiedJulianDay (enumFromTo a b)
 	enumFromThenTo (ModifiedJulianDay a) (ModifiedJulianDay b) (ModifiedJulianDay c) = fmap ModifiedJulianDay (enumFromThenTo a b c)
 
+-- necessary because H98 doesn't have "cunning newtype" derivation
+instance Ix Day where
+	range (ModifiedJulianDay a,ModifiedJulianDay b) = fmap ModifiedJulianDay (range (a,b))
+	index (ModifiedJulianDay a,ModifiedJulianDay b) (ModifiedJulianDay c) = index (a,b) c
+	inRange (ModifiedJulianDay a,ModifiedJulianDay b) (ModifiedJulianDay c) = inRange (a,b) c
+	rangeSize (ModifiedJulianDay a,ModifiedJulianDay b) = rangeSize (a,b)
+
 addDays :: Integer -> Day -> Day
 addDays n (ModifiedJulianDay a) = ModifiedJulianDay (a + n)
 



More information about the ghc-commits mailing list