    {-# LANGUAGE CPP                        #-}
    {-# LANGUAGE DeriveFunctor              #-}
    {-# LANGUAGE FlexibleContexts           #-}
    {-# LANGUAGE FlexibleInstances          #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE MultiParamTypeClasses      #-}
    {-# LANGUAGE ScopedTypeVariables        #-}
    {-# LANGUAGE TemplateHaskell            #-}
    {-# LANGUAGE TypeFamilies               #-}
    {-# LANGUAGE TypeOperators              #-}
    {-# LANGUAGE TypeSynonymInstances       #-}
    {-# LANGUAGE UndecidableInstances       #-}
    {-# LANGUAGE ViewPatterns               #-}
    -- UndecidableInstances needed for ghc < 707

    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Data.Active
    -- Copyright   :  (c) 2011 Brent Yorgey
    -- License     :  BSD-style (see LICENSE)
    -- Maintainer  :  byorgey@cis.upenn.edu
    --
    -- Inspired by the work of Kevin Matlage and Andy Gill (/Every/
    -- /Animation Should Have a Beginning, a Middle, and an End/, Trends
    -- in Functional Programming,
    -- 2010. <http://ku-fpg.github.io/files/Matlage-10-BeginningMiddleEnd.pdf>), this module defines a
    -- simple abstraction for working with time-varying values.  A value
    -- of type @Active a@ is either a constant value of type @a@, or a
    -- time-varying value of type @a@ (/i.e./ a function from time to
    -- @a@) with specific start and end times.  Since active values
    -- have start and end times, they can be aligned, sequenced,
    -- stretched, or reversed.
    --
    -- In a sense, this is sort of like a stripped-down version of
    -- functional reactive programming (FRP), without the reactivity.
    --
    -- The original motivating use for this library is to support making
    -- animations with the diagrams framework
    -- (<https://diagrams.github.io>), but the hope is that it
    -- may find more general utility.
    --
    -- There are two basic ways to create an @Active@ value.  The first is
    -- to use 'mkActive' to create one directly, by specifying a start and
    -- end time and a function of time.  More indirectly, one can use the
    -- 'Applicative' instance together with the unit interval 'ui', which
    -- takes on values from the unit interval from time 0 to time 1, or
    -- 'interval', which creates an active over an arbitrary interval.
    --
    -- For example, to create a value of type @Active Double@ which
    -- represents one period of a sine wave starting at time 0 and ending
    -- at time 1, we could write
    --
    -- > mkActive 0 1 (\t -> sin (fromTime t * tau))
    --
    -- or
    --
    -- > (sin . (*tau)) <$> ui
    --
    -- 'pure' can also be used to create @Active@ values which are
    -- constant and have no start or end time.  For example,
    --
    -- > mod <$> (floor <$> interval 0 100) <*> pure 7
    --
    -- cycles repeatedly through the numbers 0-6.
    --
    -- Note that the \"idiom bracket\" notation supported by the SHE
    -- preprocessor (<http://personal.cis.strath.ac.uk/~conor/pub/she/>,
    -- <http://hackage.haskell.org/package/she>) can make for somewhat
    -- more readable 'Applicative' code.  For example, the above example
    -- can be rewritten using SHE as
    --
    -- > {-# OPTIONS_GHC -F -pgmF she #-}
    -- >
    -- > ... (| mod (| floor (interval 0 100) |) ~7 |)
    --
    -- There are many functions for transforming and composing active
    -- values; see the documentation below for more details.
    --
    --
    -- With careful handling, this module should be suitable to generating
    -- deep embeddings if 'Active' values.
    --
    -----------------------------------------------------------------------------

    module Data.Active
           ( -- * Representing time

             -- ** Time and duration

             Time, toTime, fromTime
           , Duration, toDuration, fromDuration

             -- ** Eras

           , Era, mkEra
           , start, end, duration

             -- * Dynamic values
           , Dynamic(..), mkDynamic, onDynamic

           , shiftDynamic

             -- * Active values
             -- $active
           , Active, mkActive, fromDynamic, isConstant, isDynamic

           , onActive, modActive, runActive

           , activeEra, setEra, atTime

           , activeStart, activeEnd

             -- * Combinators

             -- ** Special active values

           , ui, interval

             -- ** Transforming active values

           , stretch, stretchTo, during
           , shift, backwards

           , snapshot

             -- ** Working with values outside the era
           , clamp, clampBefore, clampAfter
           , trim, trimBefore, trimAfter

             -- ** Composing active values

           , after

           , (->>)

           , (|>>), movie

             -- * Discretization

           , discrete
           , simulate

           ) where

    #if __GLASGOW_HASKELL__ < 710
    import           Control.Applicative
    #endif

    import           Control.Arrow       ((&&&))
    import           Control.Lens        hiding (backwards, (<.>))

    import           Data.Functor.Apply
    import           Data.Maybe
    import           Data.Monoid         (First (..))
    import           Data.Semigroup      hiding (First (..))
    import qualified Data.Vector         as V

    import           Linear
    import           Linear.Affine

    ------------------------------------------------------------
    -- Time
    ------------------------------------------------------------

    -- | An abstract type for representing /points in time/.  Note that
    --   literal numeric values may be used as @Time@s, thanks to the the
    --   'Num' and 'Fractional' instances.
    newtype Time n = Time { forall n. Time n -> n
    unTime :: n }
      deriving (Time n -> Time n -> Bool
    (Time n -> Time n -> Bool)
    -> (Time n -> Time n -> Bool) -> Eq (Time n)
    forall n. Eq n => Time n -> Time n -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall n. Eq n => Time n -> Time n -> Bool
    == :: Time n -> Time n -> Bool
    $c/= :: forall n. Eq n => Time n -> Time n -> Bool
    /= :: Time n -> Time n -> Bool
    Eq, Eq (Time n)
    Eq (Time n)
    -> (Time n -> Time n -> Ordering)
    -> (Time n -> Time n -> Bool)
    -> (Time n -> Time n -> Bool)
    -> (Time n -> Time n -> Bool)
    -> (Time n -> Time n -> Bool)
    -> (Time n -> Time n -> Time n)
    -> (Time n -> Time n -> Time n)
    -> Ord (Time n)
    Time n -> Time n -> Bool
    Time n -> Time n -> Ordering
    Time n -> Time n -> Time n
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall {n}. Ord n => Eq (Time n)
    forall n. Ord n => Time n -> Time n -> Bool
    forall n. Ord n => Time n -> Time n -> Ordering
    forall n. Ord n => Time n -> Time n -> Time n
    $ccompare :: forall n. Ord n => Time n -> Time n -> Ordering
    compare :: Time n -> Time n -> Ordering
    $c< :: forall n. Ord n => Time n -> Time n -> Bool
    < :: Time n -> Time n -> Bool
    $c<= :: forall n. Ord n => Time n -> Time n -> Bool
    <= :: Time n -> Time n -> Bool
    $c> :: forall n. Ord n => Time n -> Time n -> Bool
    > :: Time n -> Time n -> Bool
    $c>= :: forall n. Ord n => Time n -> Time n -> Bool
    >= :: Time n -> Time n -> Bool
    $cmax :: forall n. Ord n => Time n -> Time n -> Time n
    max :: Time n -> Time n -> Time n
    $cmin :: forall n. Ord n => Time n -> Time n -> Time n
    min :: Time n -> Time n -> Time n
    Ord, Int -> Time n -> ShowS
    [Time n] -> ShowS
    Time n -> String
    (Int -> Time n -> ShowS)
    -> (Time n -> String) -> ([Time n] -> ShowS) -> Show (Time n)
    forall n. Show n => Int -> Time n -> ShowS
    forall n. Show n => [Time n] -> ShowS
    forall n. Show n => Time n -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Time n -> ShowS
    showsPrec :: Int -> Time n -> ShowS
    $cshow :: forall n. Show n => Time n -> String
    show :: Time n -> String
    $cshowList :: forall n. Show n => [Time n] -> ShowS
    showList :: [Time n] -> ShowS
    Show, ReadPrec [Time n]
    ReadPrec (Time n)
    Int -> ReadS (Time n)
    ReadS [Time n]
    (Int -> ReadS (Time n))
    -> ReadS [Time n]
    -> ReadPrec (Time n)
    -> ReadPrec [Time n]
    -> Read (Time n)
    forall n. Read n => ReadPrec [Time n]
    forall n. Read n => ReadPrec (Time n)
    forall n. Read n => Int -> ReadS (Time n)
    forall n. Read n => ReadS [Time n]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall n. Read n => Int -> ReadS (Time n)
    readsPrec :: Int -> ReadS (Time n)
    $creadList :: forall n. Read n => ReadS [Time n]
    readList :: ReadS [Time n]
    $creadPrec :: forall n. Read n => ReadPrec (Time n)
    readPrec :: ReadPrec (Time n)
    $creadListPrec :: forall n. Read n => ReadPrec [Time n]
    readListPrec :: ReadPrec [Time n]
    Read, Int -> Time n
    Time n -> Int
    Time n -> [Time n]
    Time n -> Time n
    Time n -> Time n -> [Time n]
    Time n -> Time n -> Time n -> [Time n]
    (Time n -> Time n)
    -> (Time n -> Time n)
    -> (Int -> Time n)
    -> (Time n -> Int)
    -> (Time n -> [Time n])
    -> (Time n -> Time n -> [Time n])
    -> (Time n -> Time n -> [Time n])
    -> (Time n -> Time n -> Time n -> [Time n])
    -> Enum (Time n)
    forall n. Enum n => Int -> Time n
    forall n. Enum n => Time n -> Int
    forall n. Enum n => Time n -> [Time n]
    forall n. Enum n => Time n -> Time n
    forall n. Enum n => Time n -> Time n -> [Time n]
    forall n. Enum n => Time n -> Time n -> Time n -> [Time n]
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: forall n. Enum n => Time n -> Time n
    succ :: Time n -> Time n
    $cpred :: forall n. Enum n => Time n -> Time n
    pred :: Time n -> Time n
    $ctoEnum :: forall n. Enum n => Int -> Time n
    toEnum :: Int -> Time n
    $cfromEnum :: forall n. Enum n => Time n -> Int
    fromEnum :: Time n -> Int
    $cenumFrom :: forall n. Enum n => Time n -> [Time n]
    enumFrom :: Time n -> [Time n]
    $cenumFromThen :: forall n. Enum n => Time n -> Time n -> [Time n]
    enumFromThen :: Time n -> Time n -> [Time n]
    $cenumFromTo :: forall n. Enum n => Time n -> Time n -> [Time n]
    enumFromTo :: Time n -> Time n -> [Time n]
    $cenumFromThenTo :: forall n. Enum n => Time n -> Time n -> Time n -> [Time n]
    enumFromThenTo :: Time n -> Time n -> Time n -> [Time n]
    Enum, Integer -> Time n
    Time n -> Time n
    Time n -> Time n -> Time n
    (Time n -> Time n -> Time n)
    -> (Time n -> Time n -> Time n)
    -> (Time n -> Time n -> Time n)
    -> (Time n -> Time n)
    -> (Time n -> Time n)
    -> (Time n -> Time n)
    -> (Integer -> Time n)
    -> Num (Time n)
    forall n. Num n => Integer -> Time n
    forall n. Num n => Time n -> Time n
    forall n. Num n => Time n -> Time n -> Time n
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: forall n. Num n => Time n -> Time n -> Time n
    + :: Time n -> Time n -> Time n
    $c- :: forall n. Num n => Time n -> Time n -> Time n
    - :: Time n -> Time n -> Time n
    $c* :: forall n. Num n => Time n -> Time n -> Time n
    * :: Time n -> Time n -> Time n
    $cnegate :: forall n. Num n => Time n -> Time n
    negate :: Time n -> Time n
    $cabs :: forall n. Num n => Time n -> Time n
    abs :: Time n -> Time n
    $csignum :: forall n. Num n => Time n -> Time n
    signum :: Time n -> Time n
    $cfromInteger :: forall n. Num n => Integer -> Time n
    fromInteger :: Integer -> Time n
    Num, Num (Time n)
    Num (Time n)
    -> (Time n -> Time n -> Time n)
    -> (Time n -> Time n)
    -> (Rational -> Time n)
    -> Fractional (Time n)
    Rational -> Time n
    Time n -> Time n
    Time n -> Time n -> Time n
    forall {n}. Fractional n => Num (Time n)
    forall n. Fractional n => Rational -> Time n
    forall n. Fractional n => Time n -> Time n
    forall n. Fractional n => Time n -> Time n -> Time n
    forall a.
    Num a
    -> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
    $c/ :: forall n. Fractional n => Time n -> Time n -> Time n
    / :: Time n -> Time n -> Time n
    $crecip :: forall n. Fractional n => Time n -> Time n
    recip :: Time n -> Time n
    $cfromRational :: forall n. Fractional n => Rational -> Time n
    fromRational :: Rational -> Time n
    Fractional, Num (Time n)
    Ord (Time n)
    Num (Time n)
    -> Ord (Time n) -> (Time n -> Rational) -> Real (Time n)
    Time n -> Rational
    forall a. Num a -> Ord a -> (a -> Rational) -> Real a
    forall {n}. Real n => Num (Time n)
    forall {n}. Real n => Ord (Time n)
    forall n. Real n => Time n -> Rational
    $ctoRational :: forall n. Real n => Time n -> Rational
    toRational :: Time n -> Rational
    Real, Fractional (Time n)
    Real (Time n)
    Real (Time n)
    -> Fractional (Time n)
    -> (forall b. Integral b => Time n -> (b, Time n))
    -> (forall b. Integral b => Time n -> b)
    -> (forall b. Integral b => Time n -> b)
    -> (forall b. Integral b => Time n -> b)
    -> (forall b. Integral b => Time n -> b)
    -> RealFrac (Time n)
    forall b. Integral b => Time n -> b
    forall b. Integral b => Time n -> (b, Time n)
    forall a.
    Real a
    -> Fractional a
    -> (forall b. Integral b => a -> (b, a))
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> RealFrac a
    forall {n}. RealFrac n => Fractional (Time n)
    forall {n}. RealFrac n => Real (Time n)
    forall n b. (RealFrac n, Integral b) => Time n -> b
    forall n b. (RealFrac n, Integral b) => Time n -> (b, Time n)
    $cproperFraction :: forall n b. (RealFrac n, Integral b) => Time n -> (b, Time n)
    properFraction :: forall b. Integral b => Time n -> (b, Time n)
    $ctruncate :: forall n b. (RealFrac n, Integral b) => Time n -> b
    truncate :: forall b. Integral b => Time n -> b
    $cround :: forall n b. (RealFrac n, Integral b) => Time n -> b
    round :: forall b. Integral b => Time n -> b
    $cceiling :: forall n b. (RealFrac n, Integral b) => Time n -> b
    ceiling :: forall b. Integral b => Time n -> b
    $cfloor :: forall n b. (RealFrac n, Integral b) => Time n -> b
    floor :: forall b. Integral b => Time n -> b
    RealFrac, (forall a b. (a -> b) -> Time a -> Time b)
    -> (forall a b. a -> Time b -> Time a) -> Functor Time
    forall a b. a -> Time b -> Time a
    forall a b. (a -> b) -> Time a -> Time b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Time a -> Time b
    fmap :: forall a b. (a -> b) -> Time a -> Time b
    $c<$ :: forall a b. a -> Time b -> Time a
    <$ :: forall a b. a -> Time b -> Time a
    Functor)

    makeWrapped ''Time

    -- | A convenient wrapper function to convert a numeric value into a time.
    toTime :: n -> Time n
    toTime :: forall n. n -> Time n
    toTime = n -> Time n
    forall n. n -> Time n
    Time

    -- | A convenient unwrapper function to turn a time into a numeric value.
    fromTime :: Time n -> n
    fromTime :: forall n. Time n -> n
    fromTime = Time n -> n
    forall n. Time n -> n
    unTime

    -- instance Deadline Time a where
    --   -- choose tm deadline (if before / at deadline) (if after deadline)
    --   choose t1 t2 a b = if t1 <= t2 then a else b

    -- | An abstract type representing /elapsed time/ between two points
    --   in time.  Note that durations can be negative. Literal numeric
    --   values may be used as @Duration@s thanks to the 'Num' and
    --   'Fractional' instances.
    newtype Duration n = Duration n
      deriving (Duration n -> Duration n -> Bool
    (Duration n -> Duration n -> Bool)
    -> (Duration n -> Duration n -> Bool) -> Eq (Duration n)
    forall n. Eq n => Duration n -> Duration n -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall n. Eq n => Duration n -> Duration n -> Bool
    == :: Duration n -> Duration n -> Bool
    $c/= :: forall n. Eq n => Duration n -> Duration n -> Bool
    /= :: Duration n -> Duration n -> Bool
    Eq, Eq (Duration n)
    Eq (Duration n)
    -> (Duration n -> Duration n -> Ordering)
    -> (Duration n -> Duration n -> Bool)
    -> (Duration n -> Duration n -> Bool)
    -> (Duration n -> Duration n -> Bool)
    -> (Duration n -> Duration n -> Bool)
    -> (Duration n -> Duration n -> Duration n)
    -> (Duration n -> Duration n -> Duration n)
    -> Ord (Duration n)
    Duration n -> Duration n -> Bool
    Duration n -> Duration n -> Ordering
    Duration n -> Duration n -> Duration n
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall {n}. Ord n => Eq (Duration n)
    forall n. Ord n => Duration n -> Duration n -> Bool
    forall n. Ord n => Duration n -> Duration n -> Ordering
    forall n. Ord n => Duration n -> Duration n -> Duration n
    $ccompare :: forall n. Ord n => Duration n -> Duration n -> Ordering
    compare :: Duration n -> Duration n -> Ordering
    $c< :: forall n. Ord n => Duration n -> Duration n -> Bool
    < :: Duration n -> Duration n -> Bool
    $c<= :: forall n. Ord n => Duration n -> Duration n -> Bool
    <= :: Duration n -> Duration n -> Bool
    $c> :: forall n. Ord n => Duration n -> Duration n -> Bool
    > :: Duration n -> Duration n -> Bool
    $c>= :: forall n. Ord n => Duration n -> Duration n -> Bool
    >= :: Duration n -> Duration n -> Bool
    $cmax :: forall n. Ord n => Duration n -> Duration n -> Duration n
    max :: Duration n -> Duration n -> Duration n
    $cmin :: forall n. Ord n => Duration n -> Duration n -> Duration n
    min :: Duration n -> Duration n -> Duration n
    Ord, Int -> Duration n -> ShowS
    [Duration n] -> ShowS
    Duration n -> String
    (Int -> Duration n -> ShowS)
    -> (Duration n -> String)
    -> ([Duration n] -> ShowS)
    -> Show (Duration n)
    forall n. Show n => Int -> Duration n -> ShowS
    forall n. Show n => [Duration n] -> ShowS
    forall n. Show n => Duration n -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Duration n -> ShowS
    showsPrec :: Int -> Duration n -> ShowS
    $cshow :: forall n. Show n => Duration n -> String
    show :: Duration n -> String
    $cshowList :: forall n. Show n => [Duration n] -> ShowS
    showList :: [Duration n] -> ShowS
    Show, ReadPrec [Duration n]
    ReadPrec (Duration n)
    Int -> ReadS (Duration n)
    ReadS [Duration n]
    (Int -> ReadS (Duration n))
    -> ReadS [Duration n]
    -> ReadPrec (Duration n)
    -> ReadPrec [Duration n]
    -> Read (Duration n)
    forall n. Read n => ReadPrec [Duration n]
    forall n. Read n => ReadPrec (Duration n)
    forall n. Read n => Int -> ReadS (Duration n)
    forall n. Read n => ReadS [Duration n]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall n. Read n => Int -> ReadS (Duration n)
    readsPrec :: Int -> ReadS (Duration n)
    $creadList :: forall n. Read n => ReadS [Duration n]
    readList :: ReadS [Duration n]
    $creadPrec :: forall n. Read n => ReadPrec (Duration n)
    readPrec :: ReadPrec (Duration n)
    $creadListPrec :: forall n. Read n => ReadPrec [Duration n]
    readListPrec :: ReadPrec [Duration n]
    Read, Int -> Duration n
    Duration n -> Int
    Duration n -> [Duration n]
    Duration n -> Duration n
    Duration n -> Duration n -> [Duration n]
    Duration n -> Duration n -> Duration n -> [Duration n]
    (Duration n -> Duration n)
    -> (Duration n -> Duration n)
    -> (Int -> Duration n)
    -> (Duration n -> Int)
    -> (Duration n -> [Duration n])
    -> (Duration n -> Duration n -> [Duration n])
    -> (Duration n -> Duration n -> [Duration n])
    -> (Duration n -> Duration n -> Duration n -> [Duration n])
    -> Enum (Duration n)
    forall n. Enum n => Int -> Duration n
    forall n. Enum n => Duration n -> Int
    forall n. Enum n => Duration n -> [Duration n]
    forall n. Enum n => Duration n -> Duration n
    forall n. Enum n => Duration n -> Duration n -> [Duration n]
    forall n.
    Enum n =>
    Duration n -> Duration n -> Duration n -> [Duration n]
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: forall n. Enum n => Duration n -> Duration n
    succ :: Duration n -> Duration n
    $cpred :: forall n. Enum n => Duration n -> Duration n
    pred :: Duration n -> Duration n
    $ctoEnum :: forall n. Enum n => Int -> Duration n
    toEnum :: Int -> Duration n
    $cfromEnum :: forall n. Enum n => Duration n -> Int
    fromEnum :: Duration n -> Int
    $cenumFrom :: forall n. Enum n => Duration n -> [Duration n]
    enumFrom :: Duration n -> [Duration n]
    $cenumFromThen :: forall n. Enum n => Duration n -> Duration n -> [Duration n]
    enumFromThen :: Duration n -> Duration n -> [Duration n]
    $cenumFromTo :: forall n. Enum n => Duration n -> Duration n -> [Duration n]
    enumFromTo :: Duration n -> Duration n -> [Duration n]
    $cenumFromThenTo :: forall n.
    Enum n =>
    Duration n -> Duration n -> Duration n -> [Duration n]
    enumFromThenTo :: Duration n -> Duration n -> Duration n -> [Duration n]
    Enum, Integer -> Duration n
    Duration n -> Duration n
    Duration n -> Duration n -> Duration n
    (Duration n -> Duration n -> Duration n)
    -> (Duration n -> Duration n -> Duration n)
    -> (Duration n -> Duration n -> Duration n)
    -> (Duration n -> Duration n)
    -> (Duration n -> Duration n)
    -> (Duration n -> Duration n)
    -> (Integer -> Duration n)
    -> Num (Duration n)
    forall n. Num n => Integer -> Duration n
    forall n. Num n => Duration n -> Duration n
    forall n. Num n => Duration n -> Duration n -> Duration n
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: forall n. Num n => Duration n -> Duration n -> Duration n
    + :: Duration n -> Duration n -> Duration n
    $c- :: forall n. Num n => Duration n -> Duration n -> Duration n
    - :: Duration n -> Duration n -> Duration n
    $c* :: forall n. Num n => Duration n -> Duration n -> Duration n
    * :: Duration n -> Duration n -> Duration n
    $cnegate :: forall n. Num n => Duration n -> Duration n
    negate :: Duration n -> Duration n
    $cabs :: forall n. Num n => Duration n -> Duration n
    abs :: Duration n -> Duration n
    $csignum :: forall n. Num n => Duration n -> Duration n
    signum :: Duration n -> Duration n
    $cfromInteger :: forall n. Num n => Integer -> Duration n
    fromInteger :: Integer -> Duration n
    Num, Num (Duration n)
    Num (Duration n)
    -> (Duration n -> Duration n -> Duration n)
    -> (Duration n -> Duration n)
    -> (Rational -> Duration n)
    -> Fractional (Duration n)
    Rational -> Duration n
    Duration n -> Duration n
    Duration n -> Duration n -> Duration n
    forall {n}. Fractional n => Num (Duration n)
    forall n. Fractional n => Rational -> Duration n
    forall n. Fractional n => Duration n -> Duration n
    forall n. Fractional n => Duration n -> Duration n -> Duration n
    forall a.
    Num a
    -> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
    $c/ :: forall n. Fractional n => Duration n -> Duration n -> Duration n
    / :: Duration n -> Duration n -> Duration n
    $crecip :: forall n. Fractional n => Duration n -> Duration n
    recip :: Duration n -> Duration n
    $cfromRational :: forall n. Fractional n => Rational -> Duration n
    fromRational :: Rational -> Duration n
    Fractional, Num (Duration n)
    Ord (Duration n)
    Num (Duration n)
    -> Ord (Duration n)
    -> (Duration n -> Rational)
    -> Real (Duration n)
    Duration n -> Rational
    forall a. Num a -> Ord a -> (a -> Rational) -> Real a
    forall {n}. Real n => Num (Duration n)
    forall {n}. Real n => Ord (Duration n)
    forall n. Real n => Duration n -> Rational
    $ctoRational :: forall n. Real n => Duration n -> Rational
    toRational :: Duration n -> Rational
    Real, Fractional (Duration n)
    Real (Duration n)
    Real (Duration n)
    -> Fractional (Duration n)
    -> (forall b. Integral b => Duration n -> (b, Duration n))
    -> (forall b. Integral b => Duration n -> b)
    -> (forall b. Integral b => Duration n -> b)
    -> (forall b. Integral b => Duration n -> b)
    -> (forall b. Integral b => Duration n -> b)
    -> RealFrac (Duration n)
    forall b. Integral b => Duration n -> b
    forall b. Integral b => Duration n -> (b, Duration n)
    forall a.
    Real a
    -> Fractional a
    -> (forall b. Integral b => a -> (b, a))
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> (forall b. Integral b => a -> b)
    -> RealFrac a
    forall {n}. RealFrac n => Fractional (Duration n)
    forall {n}. RealFrac n => Real (Duration n)
    forall n b. (RealFrac n, Integral b) => Duration n -> b
    forall n b.
    (RealFrac n, Integral b) =>
    Duration n -> (b, Duration n)
    $cproperFraction :: forall n b.
    (RealFrac n, Integral b) =>
    Duration n -> (b, Duration n)
    properFraction :: forall b. Integral b => Duration n -> (b, Duration n)
    $ctruncate :: forall n b. (RealFrac n, Integral b) => Duration n -> b
    truncate :: forall b. Integral b => Duration n -> b
    $cround :: forall n b. (RealFrac n, Integral b) => Duration n -> b
    round :: forall b. Integral b => Duration n -> b
    $cceiling :: forall n b. (RealFrac n, Integral b) => Duration n -> b
    ceiling :: forall b. Integral b => Duration n -> b
    $cfloor :: forall n b. (RealFrac n, Integral b) => Duration n -> b
    floor :: forall b. Integral b => Duration n -> b
    RealFrac, (forall a b. (a -> b) -> Duration a -> Duration b)
    -> (forall a b. a -> Duration b -> Duration a) -> Functor Duration
    forall a b. a -> Duration b -> Duration a
    forall a b. (a -> b) -> Duration a -> Duration b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Duration a -> Duration b
    fmap :: forall a b. (a -> b) -> Duration a -> Duration b
    $c<$ :: forall a b. a -> Duration b -> Duration a
    <$ :: forall a b. a -> Duration b -> Duration a
    Functor)

    -- | A convenient wrapper function to convert a numeric value into a duration.
    toDuration :: n -> Duration n
    toDuration :: forall n. n -> Duration n
    toDuration = n -> Duration n
    forall n. n -> Duration n
    Duration

    -- | A convenient unwrapper function to turn a duration into a numeric value.
    fromDuration :: Duration n -> n
    fromDuration :: forall n. Duration n -> n
    fromDuration (Duration n
    n) = n
    n

    instance Applicative Duration where
      pure :: forall n. n -> Duration n
    pure = a -> Duration a
    forall n. n -> Duration n
    Duration
      Duration a -> b
    f <*> :: forall a b. Duration (a -> b) -> Duration a -> Duration b
    <*> Duration a
    x = b -> Duration b
    forall n. n -> Duration n
    Duration (a -> b
    f a
    x)

    instance Additive Duration where
      zero :: forall a. Num a => Duration a
    zero = Duration a
    0

    instance Num n => Semigroup (Duration n) where
      <> :: Duration n -> Duration n -> Duration n
    (<>) = Duration n -> Duration n -> Duration n
    forall n. Num n => Duration n -> Duration n -> Duration n
    forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
    (^+^)

    instance Num n => Monoid (Duration n) where
      mappend :: Duration n -> Duration n -> Duration n
    mappend = Duration n -> Duration n -> Duration n
    forall a. Semigroup a => a -> a -> a
    (<>)
      mempty :: Duration n
    mempty  = Duration n
    0

    instance Affine Time where
      -- It is important that this deffinition comes *after*
      -- the 'Additive' instance of 'Duration' to build with GHC-9.0
      type Diff Time = Duration
      (Time a
    t1) .-. :: forall a. Num a => Time a -> Time a -> Diff Time a
    .-. (Time a
    t2) = a -> Duration a
    forall n. n -> Duration n
    Duration (a
    t1 a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    t2)
      (Time a
    t) .+^ :: forall a. Num a => Time a -> Diff Time a -> Time a
    .+^ (Duration a
    d) = a -> Time a
    forall n. n -> Time n
    Time (a
    t a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    d)

    makeWrapped ''Duration

    -- | An @Era@ is a concrete span of time, that is, a pair of times
    --   representing the start and end of the era. @Era@s form a
    --   semigroup: the combination of two @Era@s is the smallest @Era@
    --   which contains both.  They do not form a 'Monoid', since there is
    --   no @Era@ which acts as the identity with respect to this
    --   combining operation.
    --
    --   @Era@ is abstract. To construct @Era@ values, use 'mkEra'; to
    --   deconstruct, use 'start' and 'end'.
    newtype Era n = Era (Min (Time n), Max (Time n))
      deriving (Int -> Era n -> ShowS
    [Era n] -> ShowS
    Era n -> String
    (Int -> Era n -> ShowS)
    -> (Era n -> String) -> ([Era n] -> ShowS) -> Show (Era n)
    forall n. Show n => Int -> Era n -> ShowS
    forall n. Show n => [Era n] -> ShowS
    forall n. Show n => Era n -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Era n -> ShowS
    showsPrec :: Int -> Era n -> ShowS
    $cshow :: forall n. Show n => Era n -> String
    show :: Era n -> String
    $cshowList :: forall n. Show n => [Era n] -> ShowS
    showList :: [Era n] -> ShowS
    Show, NonEmpty (Era n) -> Era n
    Era n -> Era n -> Era n
    (Era n -> Era n -> Era n)
    -> (NonEmpty (Era n) -> Era n)
    -> (forall b. Integral b => b -> Era n -> Era n)
    -> Semigroup (Era n)
    forall b. Integral b => b -> Era n -> Era n
    forall n. Ord n => NonEmpty (Era n) -> Era n
    forall n. Ord n => Era n -> Era n -> Era n
    forall n b. (Ord n, Integral b) => b -> Era n -> Era n
    forall a.
    (a -> a -> a)
    -> (NonEmpty a -> a)
    -> (forall b. Integral b => b -> a -> a)
    -> Semigroup a
    $c<> :: forall n. Ord n => Era n -> Era n -> Era n
    <> :: Era n -> Era n -> Era n
    $csconcat :: forall n. Ord n => NonEmpty (Era n) -> Era n
    sconcat :: NonEmpty (Era n) -> Era n
    $cstimes :: forall n b. (Ord n, Integral b) => b -> Era n -> Era n
    stimes :: forall b. Integral b => b -> Era n -> Era n
    Semigroup)

    -- | Create an 'Era' by specifying start and end 'Time's.
    mkEra :: Time n -> Time n -> Era n
    mkEra :: forall n. Time n -> Time n -> Era n
    mkEra Time n
    s Time n
    e = (Min (Time n), Max (Time n)) -> Era n
    forall n. (Min (Time n), Max (Time n)) -> Era n
    Era (Time n -> Min (Time n)
    forall a. a -> Min a
    Min Time n
    s, Time n -> Max (Time n)
    forall a. a -> Max a
    Max Time n
    e)

    -- | Get the start 'Time' of an 'Era'.
    start :: Era n -> Time n
    start :: forall n. Era n -> Time n
    start (Era (Min Time n
    t, Max (Time n)
    _)) = Time n
    t

    -- | Get the end 'Time' of an 'Era'.
    end :: Era n -> Time n
    end :: forall n. Era n -> Time n
    end (Era (Min (Time n)
    _, Max Time n
    t)) = Time n
    t

    -- | Compute the 'Duration' of an 'Era'.
    duration :: Num n => Era n -> Duration n
    duration :: forall n. Num n => Era n -> Duration n
    duration = Time n -> Time n -> Diff Time n
    Time n -> Time n -> Duration n
    forall a. Num a => Time a -> Time a -> Diff Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
    (.-.) (Time n -> Time n -> Duration n)
    -> (Era n -> Time n) -> Era n -> Time n -> Duration n
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Era n -> Time n
    forall n. Era n -> Time n
    end (Era n -> Time n -> Duration n)
    -> (Era n -> Time n) -> Era n -> Duration n
    forall a b. (Era n -> a -> b) -> (Era n -> a) -> Era n -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Era n -> Time n
    forall n. Era n -> Time n
    start

    ------------------------------------------------------------
    -- Dynamic
    ------------------------------------------------------------

    -- | A @Dynamic a@ can be thought of as an @a@ value that changes over
    --   the course of a particular 'Era'.  It's envisioned that @Dynamic@
    --   will be mostly an internal implementation detail and that
    --   'Active' will be most commonly used.  But you never know what
    --   uses people might find for things.

    data Dynamic a = Dynamic { forall a. Dynamic a -> Era Rational
    era        :: Era Rational
                             , forall a. Dynamic a -> Time Rational -> a
    runDynamic :: Time Rational -> a
                             }
      deriving (forall a b. (a -> b) -> Dynamic a -> Dynamic b)
    -> (forall a b. a -> Dynamic b -> Dynamic a) -> Functor Dynamic
    forall a b. a -> Dynamic b -> Dynamic a
    forall a b. (a -> b) -> Dynamic a -> Dynamic b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Dynamic a -> Dynamic b
    fmap :: forall a b. (a -> b) -> Dynamic a -> Dynamic b
    $c<$ :: forall a b. a -> Dynamic b -> Dynamic a
    <$ :: forall a b. a -> Dynamic b -> Dynamic a
    Functor

    -- | 'Dynamic' is an instance of 'Apply' (/i.e./ 'Applicative' without
    --   'pure'): a time-varying function is applied to a time-varying
    --   value pointwise; the era of the result is the combination of the
    --   function and value eras.  Note, however, that 'Dynamic' is /not/
    --   an instance of 'Applicative' since there is no way to implement
    --   'pure': the era would have to be empty, but there is no such
    --   thing as an empty era (that is, 'Era' is not an instance of
    --   'Monoid').

    instance Apply Dynamic where
      (Dynamic Era Rational
    d1 Time Rational -> a -> b
    f1) <.> :: forall a b. Dynamic (a -> b) -> Dynamic a -> Dynamic b
    <.> (Dynamic Era Rational
    d2 Time Rational -> a
    f2) = Era Rational -> (Time Rational -> b) -> Dynamic b
    forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
    Dynamic (Era Rational
    d1 Era Rational -> Era Rational -> Era Rational
    forall a. Semigroup a => a -> a -> a
    <> Era Rational
    d2) (Time Rational -> a -> b
    f1 (Time Rational -> a -> b)
    -> (Time Rational -> a) -> Time Rational -> b
    forall a b.
    (Time Rational -> a -> b)
    -> (Time Rational -> a) -> Time Rational -> b
    forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
    <.> Time Rational -> a
    f2)

    -- | @'Dynamic' a@ is a 'Semigroup' whenever @a@ is: the eras are
    --   combined according to their semigroup structure, and the values
    --   of type @a@ are combined pointwise.  Note that @'Dynamic' a@ cannot
    --   be an instance of 'Monoid' since 'Era' is not.
    instance Semigroup a => Semigroup (Dynamic a) where
      Dynamic Era Rational
    d1 Time Rational -> a
    f1 <> :: Dynamic a -> Dynamic a -> Dynamic a
    <> Dynamic Era Rational
    d2 Time Rational -> a
    f2 = Era Rational -> (Time Rational -> a) -> Dynamic a
    forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
    Dynamic (Era Rational
    d1 Era Rational -> Era Rational -> Era Rational
    forall a. Semigroup a => a -> a -> a
    <> Era Rational
    d2) (Time Rational -> a
    f1 (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
    forall a. Semigroup a => a -> a -> a
    <> Time Rational -> a
    f2)

    -- | Create a 'Dynamic' from a start time, an end time, and a
    --   time-varying value.
    mkDynamic :: Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic :: forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e = Era Rational -> (Time Rational -> a) -> Dynamic a
    forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
    Dynamic (Time Rational -> Time Rational -> Era Rational
    forall n. Time n -> Time n -> Era n
    mkEra Time Rational
    s Time Rational
    e)

    -- | Fold for 'Dynamic'.
    onDynamic :: (Time Rational -> Time Rational -> (Time Rational -> a) -> b) -> Dynamic a -> b
    onDynamic :: forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic Time Rational -> Time Rational -> (Time Rational -> a) -> b
    f (Dynamic Era Rational
    e Time Rational -> a
    d) = Time Rational -> Time Rational -> (Time Rational -> a) -> b
    f (Era Rational -> Time Rational
    forall n. Era n -> Time n
    start Era Rational
    e) (Era Rational -> Time Rational
    forall n. Era n -> Time n
    end Era Rational
    e) Time Rational -> a
    d

    -- | Shift a 'Dynamic' value by a certain duration.
    shiftDynamic :: Duration Rational -> Dynamic a -> Dynamic a
    shiftDynamic :: forall a. Duration Rational -> Dynamic a -> Dynamic a
    shiftDynamic Duration Rational
    sh =
      (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a
    -> Dynamic a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic
          (Time Rational
    s Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .+^ Diff Time Rational
    Duration Rational
    sh)
          (Time Rational
    e Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .+^ Diff Time Rational
    Duration Rational
    sh)
          (\Time Rational
    t -> Time Rational -> a
    d (Time Rational
    t Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .-^ Diff Time Rational
    Duration Rational
    sh))

    ------------------------------------------------------------
    --  Active
    ------------------------------------------------------------

    -- $active
    -- For working with time-varying values, it is convenient to have an
    -- 'Applicative' instance: '<*>' lets us apply time-varying
    -- functions to time-varying values; 'pure' allows treating constants
    -- as time-varying values which do not vary.  However, as explained in
    -- its documentation, 'Dynamic' cannot be made an instance of
    -- 'Applicative' since there is no way to implement 'pure'.  The
    -- problem is that all 'Dynamic' values must have a finite start and
    -- end time.  The solution is to adjoin a special constructor for
    -- pure/constant values with no start or end time, giving us 'Active'.

    -- | There are two types of @Active@ values:
    --
    --   * An 'Active' can simply be a 'Dynamic', that is, a time-varying
    --     value with start and end times.
    --
    --   * An 'Active' value can also be a constant: a single value,
    --     constant across time, with no start and end times.
    --
    --   The addition of constant values enable 'Monoid' and 'Applicative'
    --   instances for 'Active'.
    newtype Active a = Active (MaybeApply Dynamic a)
      deriving ((forall a b. (a -> b) -> Active a -> Active b)
    -> (forall a b. a -> Active b -> Active a) -> Functor Active
    forall a b. a -> Active b -> Active a
    forall a b. (a -> b) -> Active a -> Active b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Active a -> Active b
    fmap :: forall a b. (a -> b) -> Active a -> Active b
    $c<$ :: forall a b. a -> Active b -> Active a
    <$ :: forall a b. a -> Active b -> Active a
    Functor, Functor Active
    Functor Active
    -> (forall a b. Active (a -> b) -> Active a -> Active b)
    -> (forall a b. Active a -> Active b -> Active b)
    -> (forall a b. Active a -> Active b -> Active a)
    -> (forall a b c.
        (a -> b -> c) -> Active a -> Active b -> Active c)
    -> Apply Active
    forall a b. Active a -> Active b -> Active a
    forall a b. Active a -> Active b -> Active b
    forall a b. Active (a -> b) -> Active a -> Active b
    forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    forall (f :: * -> *).
    Functor f
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> Apply f
    $c<.> :: forall a b. Active (a -> b) -> Active a -> Active b
    <.> :: forall a b. Active (a -> b) -> Active a -> Active b
    $c.> :: forall a b. Active a -> Active b -> Active b
    .> :: forall a b. Active a -> Active b -> Active b
    $c<. :: forall a b. Active a -> Active b -> Active a
    <. :: forall a b. Active a -> Active b -> Active a
    $cliftF2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    liftF2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    Apply, Functor Active
    Functor Active
    -> (forall a. a -> Active a)
    -> (forall a b. Active (a -> b) -> Active a -> Active b)
    -> (forall a b c.
        (a -> b -> c) -> Active a -> Active b -> Active c)
    -> (forall a b. Active a -> Active b -> Active b)
    -> (forall a b. Active a -> Active b -> Active a)
    -> Applicative Active
    forall a. a -> Active a
    forall a b. Active a -> Active b -> Active a
    forall a b. Active a -> Active b -> Active b
    forall a b. Active (a -> b) -> Active a -> Active b
    forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    forall (f :: * -> *).
    Functor f
    -> (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    $cpure :: forall a. a -> Active a
    pure :: forall a. a -> Active a
    $c<*> :: forall a b. Active (a -> b) -> Active a -> Active b
    <*> :: forall a b. Active (a -> b) -> Active a -> Active b
    $cliftA2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    liftA2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
    $c*> :: forall a b. Active a -> Active b -> Active b
    *> :: forall a b. Active a -> Active b -> Active b
    $c<* :: forall a b. Active a -> Active b -> Active a
    <* :: forall a b. Active a -> Active b -> Active a
    Applicative)

    makeWrapped ''Active

    active :: Iso' (Active a) (Either (Dynamic a) a)
    active :: forall a (p :: * -> * -> *) (f :: * -> *).
    (Profunctor p, Functor f) =>
    p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
    -> p (Active a) (f (Active a))
    active = p (Unwrapped (Active a)) (f (Unwrapped (Active a)))
    -> p (Active a) (f (Active a))
    p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a))
    -> p (Active a) (f (Active a))
    forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
    Iso
      (Active a) (Active a) (Unwrapped (Active a)) (Unwrapped (Active a))
    _Wrapped (p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a))
     -> p (Active a) (f (Active a)))
    -> (p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
        -> p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a)))
    -> p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
    -> p (Active a) (f (Active a))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (MaybeApply Dynamic a -> Either (Dynamic a) a)
    -> (Either (Dynamic a) a -> MaybeApply Dynamic a)
    -> Iso
         (MaybeApply Dynamic a)
         (MaybeApply Dynamic a)
         (Either (Dynamic a) a)
         (Either (Dynamic a) a)
    forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
    iso MaybeApply Dynamic a -> Either (Dynamic a) a
    forall (f :: * -> *) a. MaybeApply f a -> Either (f a) a
    runMaybeApply Either (Dynamic a) a -> MaybeApply Dynamic a
    forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
    MaybeApply

    -- | Active values over a type with a 'Semigroup' instance are also an
    --   instance of 'Semigroup'.  Two active values are combined
    --   pointwise; the resulting value is constant iff both inputs are.
    instance Semigroup a => Semigroup (Active a) where
      (Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
    -> Active a -> Either (Dynamic a) a
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
    forall a (p :: * -> * -> *) (f :: * -> *).
    (Profunctor p, Functor f) =>
    p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
    -> p (Active a) (f (Active a))
    active -> Either (Dynamic a) a
    a) <> :: Active a -> Active a -> Active a
    <> (Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
    -> Active a -> Either (Dynamic a) a
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
    forall a (p :: * -> * -> *) (f :: * -> *).
    (Profunctor p, Functor f) =>
    p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
    -> p (Active a) (f (Active a))
    active -> Either (Dynamic a) a
    b) = AReview (Active a) (Either (Dynamic a) a)
    -> Either (Dynamic a) a -> Active a
    forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
    review AReview (Active a) (Either (Dynamic a) a)
    forall a (p :: * -> * -> *) (f :: * -> *).
    (Profunctor p, Functor f) =>
    p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
    -> p (Active a) (f (Active a))
    active (Either (Dynamic a) a -> Active a)
    -> Either (Dynamic a) a -> Active a
    forall a b. (a -> b) -> a -> b
    $ Either (Dynamic a) a
    -> Either (Dynamic a) a -> Either (Dynamic a) a
    forall {a}.
    Semigroup a =>
    Either (Dynamic a) a
    -> Either (Dynamic a) a -> Either (Dynamic a) a
    combine Either (Dynamic a) a
    a Either (Dynamic a) a
    b
       where
         combine :: Either (Dynamic a) a
    -> Either (Dynamic a) a -> Either (Dynamic a) a
    combine (Right a
    m1) (Right a
    m2)
           = a -> Either (Dynamic a) a
    forall a b. b -> Either a b
    Right (a
    m1 a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    m2)

         combine (Left (Dynamic Era Rational
    dur Time Rational -> a
    f)) (Right a
    m)
           = Dynamic a -> Either (Dynamic a) a
    forall a b. a -> Either a b
    Left (Era Rational -> (Time Rational -> a) -> Dynamic a
    forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
    Dynamic Era Rational
    dur (Time Rational -> a
    f (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
    forall a. Semigroup a => a -> a -> a
    <> a -> Time Rational -> a
    forall a b. a -> b -> a
    const a
    m))

         combine (Right a
    m) (Left (Dynamic Era Rational
    dur Time Rational -> a
    f))
           = Dynamic a -> Either (Dynamic a) a
    forall a b. a -> Either a b
    Left (Era Rational -> (Time Rational -> a) -> Dynamic a
    forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
    Dynamic Era Rational
    dur (a -> Time Rational -> a
    forall a b. a -> b -> a
    const a
    m (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
    forall a. Semigroup a => a -> a -> a
    <> Time Rational -> a
    f))

         combine (Left Dynamic a
    d1) (Left Dynamic a
    d2)
           = Dynamic a -> Either (Dynamic a) a
    forall a b. a -> Either a b
    Left (Dynamic a
    d1 Dynamic a -> Dynamic a -> Dynamic a
    forall a. Semigroup a => a -> a -> a
    <> Dynamic a
    d2)

    instance (Monoid a, Semigroup a) => Monoid (Active a) where
      mempty :: Active a
    mempty  = MaybeApply Dynamic a -> Active a
    forall a. MaybeApply Dynamic a -> Active a
    Active (Either (Dynamic a) a -> MaybeApply Dynamic a
    forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
    MaybeApply (a -> Either (Dynamic a) a
    forall a b. b -> Either a b
    Right a
    forall a. Monoid a => a
    mempty))
      mappend :: Active a -> Active a -> Active a
    mappend = Active a -> Active a -> Active a
    forall a. Semigroup a => a -> a -> a
    (<>)

    -- | Create an 'Active' value from a 'Dynamic'.
    fromDynamic :: Dynamic a -> Active a
    fromDynamic :: forall a. Dynamic a -> Active a
    fromDynamic = MaybeApply Dynamic a -> Active a
    forall a. MaybeApply Dynamic a -> Active a
    Active (MaybeApply Dynamic a -> Active a)
    -> (Dynamic a -> MaybeApply Dynamic a) -> Dynamic a -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Either (Dynamic a) a -> MaybeApply Dynamic a
    forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
    MaybeApply (Either (Dynamic a) a -> MaybeApply Dynamic a)
    -> (Dynamic a -> Either (Dynamic a) a)
    -> Dynamic a
    -> MaybeApply Dynamic a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dynamic a -> Either (Dynamic a) a
    forall a b. a -> Either a b
    Left

    -- | Create a dynamic 'Active' from a start time, an end time, and a
    --   time-varying value.
    mkActive :: Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    mkActive :: forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    mkActive Time Rational
    s Time Rational
    e Time Rational -> a
    f = Dynamic a -> Active a
    forall a. Dynamic a -> Active a
    fromDynamic (Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e Time Rational -> a
    f)

    -- | Fold for 'Active's.  Process an 'Active a', given a function to
    --   apply if it is a pure (constant) value, and a function to apply if
    --   it is a 'Dynamic'.
    onActive :: (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive :: forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive a -> b
    f Dynamic a -> b
    _ (Active (MaybeApply (Right a
    a))) = a -> b
    f a
    a
    onActive a -> b
    _ Dynamic a -> b
    f (Active (MaybeApply (Left Dynamic a
    d)))  = Dynamic a -> b
    f Dynamic a
    d

    -- | Modify an 'Active' value using a case analysis to see whether it
    --   is constant or dynamic.
    modActive
      :: (a -> b)
      -> (Dynamic a -> Dynamic b)
      -> Active a -> Active b
    modActive :: forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> b
    f Dynamic a -> Dynamic b
    g = (a -> Active b) -> (Dynamic a -> Active b) -> Active a -> Active b
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive (b -> Active b
    forall a. a -> Active a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (b -> Active b) -> (a -> b) -> a -> Active b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> b
    f) (Dynamic b -> Active b
    forall a. Dynamic a -> Active a
    fromDynamic (Dynamic b -> Active b)
    -> (Dynamic a -> Dynamic b) -> Dynamic a -> Active b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dynamic a -> Dynamic b
    g)

    -- | Interpret an 'Active' value as a function from time.
    runActive :: Active a -> Time Rational -> a
    runActive :: forall a. Active a -> Time Rational -> a
    runActive = (a -> Time Rational -> a)
    -> (Dynamic a -> Time Rational -> a)
    -> Active a
    -> Time Rational
    -> a
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive a -> Time Rational -> a
    forall a b. a -> b -> a
    const Dynamic a -> Time Rational -> a
    forall a. Dynamic a -> Time Rational -> a
    runDynamic

    -- | Get the value of an @Active a@ at the beginning of its era.
    activeStart :: Active a -> a
    activeStart :: forall a. Active a -> a
    activeStart = (a -> a) -> (Dynamic a -> a) -> Active a -> a
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive a -> a
    forall a. a -> a
    id ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
    -> Dynamic a -> a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
     -> Dynamic a -> a)
    -> (Time Rational -> Time Rational -> (Time Rational -> a) -> a)
    -> Dynamic a
    -> a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    _ Time Rational -> a
    d -> Time Rational -> a
    d Time Rational
    s)

    -- | Get the value of an @Active a@ at the end of its era.
    activeEnd :: Active a -> a
    activeEnd :: forall a. Active a -> a
    activeEnd = (a -> a) -> (Dynamic a -> a) -> Active a -> a
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive a -> a
    forall a. a -> a
    id ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
    -> Dynamic a -> a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
     -> Dynamic a -> a)
    -> (Time Rational -> Time Rational -> (Time Rational -> a) -> a)
    -> Dynamic a
    -> a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    _ Time Rational
    e Time Rational -> a
    d -> Time Rational -> a
    d Time Rational
    e)

    -- | Get the 'Era' of an 'Active' value (or 'Nothing' if it is
    --   a constant/pure value).
    activeEra :: Active a -> Maybe (Era Rational)
    activeEra :: forall a. Active a -> Maybe (Era Rational)
    activeEra = (a -> Maybe (Era Rational))
    -> (Dynamic a -> Maybe (Era Rational))
    -> Active a
    -> Maybe (Era Rational)
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive (Maybe (Era Rational) -> a -> Maybe (Era Rational)
    forall a b. a -> b -> a
    const Maybe (Era Rational)
    forall a. Maybe a
    Nothing) (Era Rational -> Maybe (Era Rational)
    forall a. a -> Maybe a
    Just (Era Rational -> Maybe (Era Rational))
    -> (Dynamic a -> Era Rational) -> Dynamic a -> Maybe (Era Rational)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Dynamic a -> Era Rational
    forall a. Dynamic a -> Era Rational
    era)

    -- | Test whether an 'Active' value is constant.
    isConstant :: Active a -> Bool
    isConstant :: forall a. Active a -> Bool
    isConstant = (a -> Bool) -> (Dynamic a -> Bool) -> Active a -> Bool
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive (Bool -> a -> Bool
    forall a b. a -> b -> a
    const Bool
    True) (Bool -> Dynamic a -> Bool
    forall a b. a -> b -> a
    const Bool
    False)

    -- | Test whether an 'Active' value is 'Dynamic'.
    isDynamic :: Active a -> Bool
    isDynamic :: forall a. Active a -> Bool
    isDynamic = (a -> Bool) -> (Dynamic a -> Bool) -> Active a -> Bool
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive (Bool -> a -> Bool
    forall a b. a -> b -> a
    const Bool
    False) (Bool -> Dynamic a -> Bool
    forall a b. a -> b -> a
    const Bool
    True)

    ------------------------------------------------------------
    --  Combinators
    ------------------------------------------------------------

    -- | @ui@ represents the /unit interval/, which takes on the value @t@
    --   at time @t@, and has as its era @[0,1]@. It is equivalent to
    --   @'interval' 0 1@, and can be visualized as follows:
    --
    --   <<diagrams/src_Data_Active_uiDia.svg#diagram=uiDia&width=200>>
    --
    --   On the x-axis is time, and the value that @ui@ takes on is on the
    --   y-axis.  The shaded portion represents the era.  Note that the
    --   value of @ui@ (as with any active) is still defined outside its
    --   era, and this can make a difference when it is combined with
    --   other active values with different eras.  Applying a function
    --   with 'fmap' affects all values, both inside and outside the era.
    --   To manipulate values outside the era specifically, see 'clamp'
    --   and 'trim'.
    --
    --   To alter the /values/ that @ui@ takes on without altering its
    --   era, use its 'Functor' and 'Applicative' instances.  For example,
    --   @(*2) \<$\> ui@ varies from @0@ to @2@ over the era @[0,1]@.  To
    --   alter the era, you can use 'stretch' or 'shift'.
    ui :: Fractional a => Active a
    ui :: forall a. Fractional a => Active a
    ui = Time Rational -> Time Rational -> Active a
    forall a.
    Fractional a =>
    Time Rational -> Time Rational -> Active a
    interval Time Rational
    0 Time Rational
    1

    -- | @interval a b@ is an active value starting at time @a@, ending at
    --   time @b@, and taking the value @t@ at time @t@.
    interval :: Fractional a => Time Rational -> Time Rational -> Active a
    interval :: forall a.
    Fractional a =>
    Time Rational -> Time Rational -> Active a
    interval Time Rational
    a Time Rational
    b = Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    mkActive Time Rational
    a Time Rational
    b (Rational -> a
    forall a. Fractional a => Rational -> a
    fromRational (Rational -> a)
    -> (Time Rational -> Rational) -> Time Rational -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Time Rational -> Rational
    forall n. Time n -> n
    unTime)

    -- | @stretch s act@ \"stretches\" the active @act@ so that it takes
    --   @s@ times as long (retaining the same start time).
    stretch :: Rational -> Active a -> Active a
    stretch :: forall a. Rational -> Active a -> Active a
    stretch Rational
    str =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s (Time Rational
    s Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .+^ (Rational
    str Rational -> Duration Rational -> Duration Rational
    forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
    *^ (Time Rational
    e Time Rational -> Time Rational -> Diff Time Rational
    forall a. Num a => Time a -> Time a -> Diff Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
    .-. Time Rational
    s)))
          (\Time Rational
    t -> Time Rational -> a
    d (Time Rational
    s Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .+^ ((Time Rational
    t Time Rational -> Time Rational -> Diff Time Rational
    forall a. Num a => Time a -> Time a -> Diff Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
    .-. Time Rational
    s) Duration Rational -> Rational -> Duration Rational
    forall (f :: * -> *) a.
    (Functor f, Fractional a) =>
    f a -> a -> f a
    ^/ Rational
    str)))

    -- | @stretchTo d@ 'stretch'es an 'Active' so it has duration @d@.
    --   Has no effect if (1) @d@ is non-positive, or (2) the 'Active'
    --   value is constant, or (3) the 'Active' value has zero duration.
    -- [AJG: conditions (1) and (3) no longer true: to consider changing]

    stretchTo :: Duration Rational -> Active a -> Active a
    stretchTo :: forall a. Duration Rational -> Active a -> Active a
    stretchTo Duration Rational
    d Active a
    a
      | Duration Rational
    d Duration Rational -> Duration Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    <= Duration Rational
    0                               = Active a
    a
      | (Era Rational -> Duration Rational
    forall n. Num n => Era n -> Duration n
    duration (Era Rational -> Duration Rational)
    -> Maybe (Era Rational) -> Maybe (Duration Rational)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active a -> Maybe (Era Rational)
    forall a. Active a -> Maybe (Era Rational)
    activeEra Active a
    a) Maybe (Duration Rational) -> Maybe (Duration Rational) -> Bool
    forall a. Eq a => a -> a -> Bool
    == Duration Rational -> Maybe (Duration Rational)
    forall a. a -> Maybe a
    Just Duration Rational
    0 = Active a
    a
      | Bool
    otherwise = Active a -> (Rational -> Active a) -> Maybe Rational -> Active a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Active a
    a (Rational -> Active a -> Active a
    forall a. Rational -> Active a -> Active a
    `stretch` Active a
    a) ((Duration Rational -> Rational
    forall a. Real a => a -> Rational
    toRational (Duration Rational -> Rational)
    -> (Era Rational -> Duration Rational) -> Era Rational -> Rational
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Duration Rational
    d Duration Rational -> Duration Rational -> Duration Rational
    forall a. Fractional a => a -> a -> a
    /) (Duration Rational -> Duration Rational)
    -> (Era Rational -> Duration Rational)
    -> Era Rational
    -> Duration Rational
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Era Rational -> Duration Rational
    forall n. Num n => Era n -> Duration n
    duration) (Era Rational -> Rational)
    -> Maybe (Era Rational) -> Maybe Rational
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active a -> Maybe (Era Rational)
    forall a. Active a -> Maybe (Era Rational)
    activeEra Active a
    a)

    -- | @a1 \`during\` a2@ 'stretch'es and 'shift's @a1@ so that it has the
    --   same era as @a2@.  Has no effect if either of @a1@ or @a2@ are constant.
    during :: Active a -> Active a -> Active a
    during :: forall a. Active a -> Active a -> Active a
    during Active a
    a1 Active a
    a2 = Active a
    -> ((Duration Rational, Time Rational) -> Active a)
    -> Maybe (Duration Rational, Time Rational)
    -> Active a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Active a
    a1 (\(Duration Rational
    d,Time Rational
    s) -> Duration Rational -> Active a -> Active a
    forall a. Duration Rational -> Active a -> Active a
    stretchTo Duration Rational
    d (Active a -> Active a)
    -> (Active a -> Active a) -> Active a -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Time Rational -> Active a -> Active a
    forall a. Time Rational -> Active a -> Active a
    atTime Time Rational
    s (Active a -> Active a) -> Active a -> Active a
    forall a b. (a -> b) -> a -> b
    $ Active a
    a1)
                     ((Era Rational -> Duration Rational
    forall n. Num n => Era n -> Duration n
    duration (Era Rational -> Duration Rational)
    -> (Era Rational -> Time Rational)
    -> Era Rational
    -> (Duration Rational, Time Rational)
    forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& Era Rational -> Time Rational
    forall n. Era n -> Time n
    start) (Era Rational -> (Duration Rational, Time Rational))
    -> Maybe (Era Rational) -> Maybe (Duration Rational, Time Rational)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active a -> Maybe (Era Rational)
    forall a. Active a -> Maybe (Era Rational)
    activeEra Active a
    a2)

    -- | @shift d act@ shifts the start time of @act@ by duration @d@.
    --   Has no effect on constant values.
    shift :: Duration Rational -> Active a -> Active a
    shift :: forall a. Duration Rational -> Active a -> Active a
    shift Duration Rational
    sh = (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id (Duration Rational -> Dynamic a -> Dynamic a
    forall a. Duration Rational -> Dynamic a -> Dynamic a
    shiftDynamic Duration Rational
    sh)

    -- | Reverse an active value so the start of its era gets mapped to
    --   the end and vice versa.  For example, @backwards 'ui'@ can be
    --   visualized as
    --
    --   <<diagrams/src_Data_Active_backwardsDia.svg#diagram=backwardsDia&width=200>>
    backwards :: Active a -> Active a
    backwards :: forall a. Active a -> Active a
    backwards =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e
          (\Time Rational
    t -> Time Rational -> a
    d (Time Rational
    s Time Rational -> Diff Time Rational -> Time Rational
    forall a. Num a => Time a -> Diff Time a -> Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
    .+^ (Time Rational
    e Time Rational -> Time Rational -> Diff Time Rational
    forall a. Num a => Time a -> Time a -> Diff Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
    .-. Time Rational
    t)))

    -- | Take a \"snapshot\" of an active value at a particular time,
    --   resulting in a constant value.
    snapshot :: Time Rational -> Active a -> Active a
    snapshot :: forall a. Time Rational -> Active a -> Active a
    snapshot Time Rational
    t Active a
    a = a -> Active a
    forall a. a -> Active a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Active a -> Time Rational -> a
    forall a. Active a -> Time Rational -> a
    runActive Active a
    a Time Rational
    t)

    -- | \"Clamp\" an active value so that it is constant before and after
    --   its era.  Before the era, @clamp a@ takes on the value of @a@ at
    --   the start of the era.  Likewise, after the era, @clamp a@ takes
    --   on the value of @a@ at the end of the era. @clamp@ has no effect
    --   on constant values.
    --
    --   For example, @clamp 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_clampDia.svg#diagram=clampDia&width=200>>
    --
    --   See also 'clampBefore' and 'clampAfter', which clamp only before
    --   or after the era, respectively.

    clamp :: Active a -> Active a
    clamp :: forall a. Active a -> Active a
    clamp =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e
          (\Time Rational
    t -> case () of ()
    _ | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    < Time Rational
    s     -> Time Rational -> a
    d Time Rational
    s
                              | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    > Time Rational
    e     -> Time Rational -> a
    d Time Rational
    e
                              | Bool
    otherwise -> Time Rational -> a
    d Time Rational
    t
          )

    -- | \"Clamp\" an active value so that it is constant before the start
    --   of its era. For example, @clampBefore 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_clampBeforeDia.svg#diagram=clampBeforeDia&width=200>>
    --
    --   See the documentation of 'clamp' for more information.
    clampBefore :: Active a -> Active a
    clampBefore :: forall a. Active a -> Active a
    clampBefore = Active a -> Active a
    forall a. HasCallStack => a
    undefined

    --- XXX These are undefined!

    -- | \"Clamp\" an active value so that it is constant after the end
    --   of its era.  For example, @clampBefore 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_clampAfterDia.svg#diagram=clampAfterDia&width=200>>
    --
    --   See the documentation of 'clamp' for more information.
    clampAfter :: Active a -> Active a
    clampAfter :: forall a. Active a -> Active a
    clampAfter = Active a -> Active a
    forall a. HasCallStack => a
    undefined

    -- | \"Trim\" an active value so that it is empty outside its era.
    --   @trim@ has no effect on constant values.
    --
    --   For example, @trim 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_trimDia.svg#diagram=trimDia&width=200>>
    --
    --   Actually, @trim ui@ is not well-typed, since it is not guaranteed
    --   that @ui@'s values will be monoidal (and usually they won't be)!
    --   But the above image still provides a good intuitive idea of what
    --   @trim@ is doing. To make this precise we could consider something
    --   like @trim (First . Just <$> ui)@.
    --
    --   See also 'trimBefore' and 'trimActive', which trim only before or
    --   after the era, respectively.

    trim :: Monoid a => Active a -> Active a
    trim :: forall a. Monoid a => Active a -> Active a
    trim =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e
          (\Time Rational
    t -> case () of ()
    _ | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    < Time Rational
    s     -> a
    forall a. Monoid a => a
    mempty
                              | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    > Time Rational
    e     -> a
    forall a. Monoid a => a
    mempty
                              | Bool
    otherwise -> Time Rational -> a
    d Time Rational
    t
          )

    -- | \"Trim\" an active value so that it is empty /before/ the start
    --   of its era. For example, @trimBefore 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_trimBeforeDia.svg#diagram=trimBeforeDia&width=200>>
    --
    --   See the documentation of 'trim' for more details.
    trimBefore :: Monoid a => Active a -> Active a
    trimBefore :: forall a. Monoid a => Active a -> Active a
    trimBefore =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e
          (\Time Rational
    t -> case () of ()
    _ | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    < Time Rational
    s     -> a
    forall a. Monoid a => a
    mempty
                              | Bool
    otherwise -> Time Rational -> a
    d Time Rational
    t
          )

    -- | \"Trim\" an active value so that it is empty /after/ the end
    --   of its era.  For example, @trimAfter 'ui'@ can be visualized as
    --
    --   <<diagrams/src_Data_Active_trimAfterDia.svg#diagram=trimAfterDia&width=200>>
    --
    --   See the documentation of 'trim' for more details.
    trimAfter :: Monoid a => Active a -> Active a
    trimAfter :: forall a. Monoid a => Active a -> Active a
    trimAfter =
      (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
    forall a b.
    (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
    modActive a -> a
    forall a. a -> a
    id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
    -> ((Time Rational
         -> Time Rational -> (Time Rational -> a) -> Dynamic a)
        -> Dynamic a -> Dynamic a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic ((Time Rational
      -> Time Rational -> (Time Rational -> a) -> Dynamic a)
     -> Active a -> Active a)
    -> (Time Rational
        -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Active a
    -> Active a
    forall a b. (a -> b) -> a -> b
    $ \Time Rational
    s Time Rational
    e Time Rational -> a
    d ->
        Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic Time Rational
    s Time Rational
    e
          (\Time Rational
    t -> case () of ()
    _ | Time Rational
    t Time Rational -> Time Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    > Time Rational
    e     -> a
    forall a. Monoid a => a
    mempty
                              | Bool
    otherwise -> Time Rational -> a
    d Time Rational
    t
          )

    -- | Set the era of an 'Active' value.  Note that this will change a
    --   constant 'Active' into a dynamic one which happens to have the
    --   same value at all times.
    setEra :: Era Rational -> Active a -> Active a
    setEra :: forall a. Era Rational -> Active a -> Active a
    setEra Era Rational
    er =
      (a -> Active a) -> (Dynamic a -> Active a) -> Active a -> Active a
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive
        (Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
    mkActive (Era Rational -> Time Rational
    forall n. Era n -> Time n
    start Era Rational
    er) (Era Rational -> Time Rational
    forall n. Era n -> Time n
    end Era Rational
    er) ((Time Rational -> a) -> Active a)
    -> (a -> Time Rational -> a) -> a -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Time Rational -> a
    forall a b. a -> b -> a
    const)
        (Dynamic a -> Active a
    forall a. Dynamic a -> Active a
    fromDynamic (Dynamic a -> Active a)
    -> (Dynamic a -> Dynamic a) -> Dynamic a -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Time Rational
     -> Time Rational -> (Time Rational -> a) -> Dynamic a)
    -> Dynamic a -> Dynamic a
    forall a b.
    (Time Rational -> Time Rational -> (Time Rational -> a) -> b)
    -> Dynamic a -> b
    onDynamic (\Time Rational
    _ Time Rational
    _ -> Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    forall a.
    Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
    mkDynamic (Era Rational -> Time Rational
    forall n. Era n -> Time n
    start Era Rational
    er) (Era Rational -> Time Rational
    forall n. Era n -> Time n
    end Era Rational
    er)))

    -- | @atTime t a@ is an active value with the same behavior as @a@,
    --   shifted so that it starts at time @t@.  If @a@ is constant it is
    --   returned unchanged.
    atTime :: Time Rational -> Active a -> Active a
    atTime :: forall a. Time Rational -> Active a -> Active a
    atTime Time Rational
    t Active a
    a = Active a
    -> (Era Rational -> Active a) -> Maybe (Era Rational) -> Active a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Active a
    a (\Era Rational
    e -> Duration Rational -> Active a -> Active a
    forall a. Duration Rational -> Active a -> Active a
    shift (Time Rational
    t Time Rational -> Time Rational -> Diff Time Rational
    forall a. Num a => Time a -> Time a -> Diff Time a
    forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
    .-. Era Rational -> Time Rational
    forall n. Era n -> Time n
    start Era Rational
    e) Active a
    a) (Active a -> Maybe (Era Rational)
    forall a. Active a -> Maybe (Era Rational)
    activeEra Active a
    a)

    -- | @a1 \`after\` a2@ produces an active that behaves like @a1@ but is
    --   shifted to start at the end time of @a2@.  If either @a1@ or @a2@
    --   are constant, @a1@ is returned unchanged.
    after :: Active a -> Active a -> Active a
    after :: forall a. Active a -> Active a -> Active a
    after Active a
    a1 Active a
    a2 = Active a
    -> (Era Rational -> Active a) -> Maybe (Era Rational) -> Active a
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Active a
    a1 ((Time Rational -> Active a -> Active a
    forall a. Time Rational -> Active a -> Active a
    `atTime` Active a
    a1) (Time Rational -> Active a)
    -> (Era Rational -> Time Rational) -> Era Rational -> Active a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Era Rational -> Time Rational
    forall n. Era n -> Time n
    end) (Active a -> Maybe (Era Rational)
    forall a. Active a -> Maybe (Era Rational)
    activeEra Active a
    a2)

    infixr 5 ->>

    -- XXX illustrate

    -- | Sequence/overlay two 'Active' values: shift the second to start
    --   immediately after the first (using 'after'), then compose them
    --   (using '<>').
    (->>) :: Semigroup a => Active a -> Active a -> Active a
    Active a
    a1 ->> :: forall a. Semigroup a => Active a -> Active a -> Active a
    ->> Active a
    a2 = Active a
    a1 Active a -> Active a -> Active a
    forall a. Semigroup a => a -> a -> a
    <> (Active a
    a2 Active a -> Active a -> Active a
    forall a. Active a -> Active a -> Active a
    `after` Active a
    a1)

    -- XXX illustrate

    -- | \"Splice\" two 'Active' values together: shift the second to
    --   start immediately after the first (using 'after'), and produce
    --   the value which acts like the first up to the common end/start
    --   point, then like the second after that.  If both are constant,
    --   return the first.
    (|>>) :: Active a -> Active a -> Active a
    Active a
    a1 |>> :: forall a. Active a -> Active a -> Active a
    |>> Active a
    a2 = (Maybe a -> a
    forall a. HasCallStack => Maybe a -> a
    fromJust (Maybe a -> a) -> (First a -> Maybe a) -> First a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . First a -> Maybe a
    forall a. First a -> Maybe a
    getFirst) (First a -> a) -> Active (First a) -> Active a
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                (Active (First a) -> Active (First a)
    forall a. Monoid a => Active a -> Active a
    trimAfter (Maybe a -> First a
    forall a. Maybe a -> First a
    First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Maybe a
    forall a. a -> Maybe a
    Just (a -> First a) -> Active a -> Active (First a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active a
    a1) Active (First a) -> Active (First a) -> Active (First a)
    forall a. Semigroup a => Active a -> Active a -> Active a
    ->> Active (First a) -> Active (First a)
    forall a. Monoid a => Active a -> Active a
    trimBefore (Maybe a -> First a
    forall a. Maybe a -> First a
    First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Maybe a
    forall a. a -> Maybe a
    Just (a -> First a) -> Active a -> Active (First a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active a
    a2))

    -- XXX implement 'movie' with a balanced fold

    -- | Splice together a list of active values using '|>>'.  The list
    --   must be nonempty.
    movie :: [Active a] -> Active a
    movie :: forall a. [Active a] -> Active a
    movie = (Active a -> Active a -> Active a) -> [Active a] -> Active a
    forall a. (a -> a -> a) -> [a] -> a
    forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
    foldr1 Active a -> Active a -> Active a
    forall a. Active a -> Active a -> Active a
    (|>>)

    ------------------------------------------------------------
    --  Discretization
    ------------------------------------------------------------

    -- | Create an @Active@ which takes on each value in the given list in
    --   turn during the time @[0,1]@, with each value getting an equal
    --   amount of time.  In other words, @discrete@ creates a \"slide
    --   show\" that starts at time 0 and ends at time 1.  The first
    --   element is used prior to time 0, and the last element is used
    --   after time 1.
    --
    --   It is an error to call @discrete@ on the empty list.
    discrete :: [a] -> Active a
    discrete :: forall a. [a] -> Active a
    discrete [] = String -> Active a
    forall a. HasCallStack => String -> a
    error String
    "Data.Active.discrete must be called with a non-empty list."
    discrete [a]
    xs = Rational -> a
    f (Rational -> a) -> Active Rational -> Active a
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Active Rational
    forall a. Fractional a => Active a
    ui
      where f :: Rational -> a
    f (Rational
    t :: Rational)
                | Rational
    t Rational -> Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    <= Rational
    0    = Vector a -> a
    forall a. Vector a -> a
    V.unsafeHead Vector a
    v
                | Rational
    t Rational -> Rational -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Rational
    1    = Vector a -> a
    forall a. Vector a -> a
    V.unsafeLast Vector a
    v
                | Bool
    otherwise = Vector a -> Int -> a
    forall a. Vector a -> Int -> a
    V.unsafeIndex Vector a
    v (Int -> a) -> Int -> a
    forall a b. (a -> b) -> a -> b
    $ Rational -> Int
    forall b. Integral b => Rational -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    floor (Rational
    t Rational -> Rational -> Rational
    forall a. Num a => a -> a -> a
    * Int -> Rational
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Vector a -> Int
    forall a. Vector a -> Int
    V.length Vector a
    v))
            v :: Vector a
    v = [a] -> Vector a
    forall a. [a] -> Vector a
    V.fromList [a]
    xs

    -- | @simulate r act@ simulates the 'Active' value @act@, returning a
    --   list of \"snapshots\" taken at regular intervals from the start
    --   time to the end time.  The interval used is determined by the
    --   rate @r@, which denotes the \"frame rate\", that is, the number
    --   of snapshots per unit time.
    --
    --   If the 'Active' value is constant (and thus has no start or end
    --   times), a list of length 1 is returned, containing the constant
    --   value.
    simulate :: Rational -> Active a -> [a]
    simulate :: forall a. Rational -> Active a -> [a]
    simulate Rational
    0    = [a] -> Active a -> [a]
    forall a b. a -> b -> a
    const []
    simulate Rational
    rate =
      (a -> [a]) -> (Dynamic a -> [a]) -> Active a -> [a]
    forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
    onActive (a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :[])
               (\Dynamic a
    d -> (Time Rational -> a) -> [Time Rational] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    map (Dynamic a -> Time Rational -> a
    forall a. Dynamic a -> Time Rational -> a
    runDynamic Dynamic a
    d)
                          (let s :: Time Rational
    s = Era Rational -> Time Rational
    forall n. Era n -> Time n
    start (Dynamic a -> Era Rational
    forall a. Dynamic a -> Era Rational
    era Dynamic a
    d)
                               e :: Time Rational
    e = Era Rational -> Time Rational
    forall n. Era n -> Time n
    end   (Dynamic a -> Era Rational
    forall a. Dynamic a -> Era Rational
    era Dynamic a
    d)
                           in  [Time Rational
    s, Time Rational
    s Time Rational -> Time Rational -> Time Rational
    forall a. Num a => a -> a -> a
    + Time Rational
    1Time Rational -> Rational -> Time Rational
    forall (f :: * -> *) a.
    (Functor f, Fractional a) =>
    f a -> a -> f a
    ^/Rational
    rate .. Time Rational
    e]
                          )
               )

    ------------------------------------------------------------
    -- Illustrations produced with diagrams-haddock
    --
    -- > d :: Diagram B -> Diagram B
    -- > d fun = (square 4 <> ends <> fun # lc red)
    -- >       # lineCap LineCapRound # lineJoin LineJoinRound
    -- >       # frame 1
    -- >   where ends = vert <> vert # translateX 1
    -- >                <> rect 1 4 # translateX (0.5) # opacity 0.2 # fc grey
    -- >         vert = vrule 4 # dashingG [0.1,0.1] 0 # lc grey
    -- >
    -- > uiDia = d $
    -- >   ((-2) ^& (-2)) ~~ (2 ^& 2)
    -- >
    -- > backwardsDia = d $
    -- >   (2 ^& (-1)) ~~ ((-1) ^& 2)
    -- >
    -- > clampDia = d $
    -- >   [(2,0), (1,1), (1,0)]
    -- >   # map r2 # fromOffsets # centerX
    -- >
    -- > clampBeforeDia = d $
    -- >   [(2,0), (2,2)]
    -- >   # map r2 # fromOffsets # centerX
    -- >
    -- > clampAfterDia = d $
    -- >   [(3,3), (1,0)]
    -- >   # map r2 # fromOffsets # centerX # translateY (-2)
    -- >
    -- > trimDia = d $ origin ~~ (1 ^& 1)
    -- >
    -- > trimBeforeDia = d $ origin ~~ (2 ^& 2)
    -- >
    -- > trimAfterDia = d $ ((-2) ^& (-2)) ~~ (1 ^& 1)