Skip to content

Commit

Permalink
add AffineSpace instance for TimeStamp
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLato committed Feb 16, 2013
1 parent 948a24c commit 7508cef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Data/ZoomCache/Common.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS -Wall #-}
----------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -39,6 +40,7 @@ module Data.ZoomCache.Common (
, Version(..)
) where

import Data.AffineSpace
import Data.Int
import Data.Ratio
import Data.Time.Clock (UTCTime, addUTCTime, diffUTCTime)
Expand Down Expand Up @@ -78,6 +80,11 @@ newtype TimeStamp = TS Double

newtype TimeStampDiff = TSDiff Double

instance AffineSpace TimeStamp where
type Diff TimeStamp = Double
TS l .-. TS r = l .-. r
TS t .+^ d = TS (t .+^ d)

-- | @timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)@
timeStampDiff :: TimeStamp -> TimeStamp -> TimeStampDiff
timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)
Expand Down
3 changes: 3 additions & 0 deletions zoom-cache.cabal
Expand Up @@ -93,6 +93,7 @@ Library
transformers >= 0.2 && < 0.4,
type-level,
unix,
vector-space,
zlib

Exposed-modules:
Expand Down Expand Up @@ -154,6 +155,7 @@ Executable zoom-cache
type-level,
ui-command,
unix,
vector-space,
zlib

Test-suite tests
Expand All @@ -171,6 +173,7 @@ Test-suite tests
transformers >= 0.2 && < 0.4,
type-level,
unix,
vector-space,
zoom-cache

------------------------------------------------------------------------
Expand Down

0 comments on commit 7508cef

Please sign in to comment.