    -- |
    -- 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 :: forall t s e (m :: * -> *) a. HasTime t s => Wire s e m a t
    time = t -> Wire s e m a t
    forall t s e (m :: * -> *) a. HasTime t s => t -> Wire s e m a t
    timeFrom t
    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 :: forall b t s (m :: * -> *) e a.
    (Fractional b, HasTime t s, Monad m) =>
    Wire s e m a b
    timeF = (t -> b) -> Wire s e m a t -> Wire s e m a b
    forall a b. (a -> b) -> Wire s e m a a -> Wire s e m a b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap t -> b
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac Wire s e m a t
    forall t s e (m :: * -> *) a. HasTime t s => Wire s e m a t
    time

    -- | Local time starting from the given value.

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