packages feed

time-domain (empty) → 0.1.0.0

raw patch · 4 files changed

+140/−0 lines, 4 filesdep +basedep +time

Dependencies added: base, time

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for time-domain++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2021 Manuel Bärenz++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ src/Data/TimeDomain.hs view
@@ -0,0 +1,93 @@+{- |+This module defines the 'TimeDomain' class.+Its instances model time,+simulated and realtime.+Several instances such as 'UTCTime', 'Double' and 'Integer' are supplied here.+-}++{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TypeFamilies #-}++module Data.TimeDomain+  ( module Data.TimeDomain+  , UTCTime+  )+  where++-- time+import Data.Time.Clock (UTCTime, diffUTCTime)++{- |+A time domain is an affine space representing a notion of time,+such as real time, simulated time, steps, or a completely different notion.++Expected law:++@(t1 `diffTime` t3) `difference` (t1 `diffTime` t2) = t2 `diffTime` t3@+-}+class TimeDifference (Diff time) => TimeDomain time where+  -- | The type of differences or durations between two timestamps+  type Diff time++  {- | Compute the difference between two timestamps.++  Mnemonic: 'diffTime' behaves like the '(-)' operator:++  @'diffTime' earlier later = later `'diffTime'` earlier@ is the duration it takes from @earlier@ to @later.+  -}+  diffTime :: time -> time -> Diff time++{- | A type of durations, or differences betweens time stamps.++For the expected law, see 'TimeDomain'.+-}+class TimeDifference d where+  -- | Calculate the difference between two durations,+  --   compatibly with 'diffTime'.+  difference :: d -> d -> d++-- | Differences between 'UTCTime's are measured in seconds.+instance TimeDomain UTCTime where+  type Diff UTCTime = Double+  diffTime t1 t2 = realToFrac $ diffUTCTime t1 t2++instance TimeDifference Double where+  difference = (-)++instance TimeDomain Double where+  type Diff Double = Double+  diffTime = (-)++instance TimeDifference Float where+  difference = (-)++instance TimeDomain Float where+  type Diff Float = Float+  diffTime = (-)++instance TimeDifference Integer where+  difference = (-)++instance TimeDomain Integer where+  type Diff Integer = Integer+  diffTime = (-)++instance TimeDifference () where+  difference _ _ = ()++instance TimeDomain () where+  type Diff () = ()+  diffTime _ _ = ()++-- | Any 'Num' can be wrapped to form a 'TimeDomain'.+newtype NumTimeDomain a = NumTimeDomain { fromNumTimeDomain :: a }+  deriving Num++instance Num a => TimeDifference (NumTimeDomain a) where+  difference = (-)++instance Num a => TimeDomain (NumTimeDomain a) where+  type Diff (NumTimeDomain a) = NumTimeDomain a+  diffTime = (-)
+ time-domain.cabal view
@@ -0,0 +1,22 @@+cabal-version:      2.4+name:               time-domain+version:            0.1.0.0+license:            MIT+license-file:       LICENSE+author:             Manuel Bärenz+maintainer:         programming@manuelbaerenz.de+synopsis:           A library for time domains and durations+description:        This library mainly provides a type class, 'TimeDomain',+                    which can be used to specify times and durations.+                    There are some instances for standard types from @base@ and @time@.+extra-source-files: CHANGELOG.md+category:           FRP+homepage:           https://github.com/turion/time-domain/++library+  exposed-modules:  Data.TimeDomain+  build-depends:+      base >= 4.13.0 && <= 4.17+    , time >= 1.9+  hs-source-dirs:   src+  default-language: Haskell2010