File: Time.hs

package info (click to toggle)
haskell-netwire 5.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: haskell: 1,326; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- |
-- Module:     Control.Wire.Time
-- Copyright:  (c) 2013 Ertugrul Soeylemez
-- License:    BSD3
-- Maintainer: Ertugrul Soeylemez <es@ertes.de>

module Control.Wire.Time
    ( -- * Time wires
      time,
      timeF,
      timeFrom
    )
    where

import Control.Wire.Core
import Control.Wire.Session


-- | Local time starting from zero.

time :: (HasTime t s) => Wire s e m a t
time = timeFrom 0


-- | Local time starting from zero, converted to your favorite
-- fractional type.

timeF :: (Fractional b, HasTime t s, Monad m) => Wire s e m a b
timeF = fmap realToFrac time


-- | Local time starting from the given value.

timeFrom :: (HasTime t s) => t -> Wire s e m a t
timeFrom t' =
    mkSF $ \ds _ ->
        let t = t' + dtime ds
        in lstrict (t, timeFrom t)