Skip to content

Commit

Permalink
TimeStamp: add VectorSpace and InnerSpace instances
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLato committed Feb 17, 2013
1 parent c8289dc commit d5db242
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Data/ZoomCache/Common.hs
Expand Up @@ -40,10 +40,12 @@ module Data.ZoomCache.Common (
, Version(..)
) where

import Data.AdditiveGroup
import Data.AffineSpace
import Data.Int
import Data.Ratio
import Data.Time.Clock (UTCTime, addUTCTime, diffUTCTime)
import Data.VectorSpace

------------------------------------------------------------

Expand Down Expand Up @@ -85,6 +87,18 @@ instance AffineSpace TimeStamp where
TS l .-. TS r = l .-. r
TS t .+^ d = TS (t .+^ d)

instance AdditiveGroup TimeStamp where
zeroV = TS zeroV
TS l ^+^ TS r = TS (l ^+^ r)
negateV (TS t) = TS (negateV t)

instance VectorSpace TimeStamp where
type Scalar TimeStamp = Double
d *^ (TS t) = TS (d*t)

instance InnerSpace TimeStamp where
TS l <.> TS r = l <.> r

-- | @timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)@
timeStampDiff :: TimeStamp -> TimeStamp -> TimeStampDiff
timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)
Expand Down

0 comments on commit d5db242

Please sign in to comment.