-- | -- Module: FRP.NetWire.Calculus -- Copyright: (c) 2011 Ertugrul Soeylemez -- License: BSD3 -- Maintainer: Ertugrul Soeylemez -- -- Calculus functions. module FRP.NetWire.Calculus ( -- * Calculus over time derivative, derivativeFrom, integral ) where import Control.DeepSeq import Data.VectorSpace import FRP.NetWire.Wire -- | Differentiate over time. Inhibits at first instant. derivative :: (NFData v, VectorSpace v, Scalar v ~ Double) => Wire v v derivative = mkGen $ \_ y2 -> return (Nothing, derivativeFrom y2) -- | Differentiate over time. The argument is the value before the -- first instant. derivativeFrom :: (NFData v, VectorSpace v, Scalar v ~ Double) => v -> Wire v v derivativeFrom y1 = mkGen $ \(wsDTime -> dt) y2 -> do let dy = (y2 ^-^ y1) ^/ dt dy `deepseq` return (Just dy, derivativeFrom y2) -- | Integrate over time. The argument is the integration constant. integral :: (NFData v, VectorSpace v, Scalar v ~ Double) => v -> Wire v v integral x1 = mkGen $ \ws dx -> do let dt = wsDTime ws x2 = x1 ^+^ dt *^ dx x2 `deepseq` return (Just x2, integral x2)