In Haskell, one can make more general combinators in the following way:
type Anim a = (Duration -> a, Maybe Duration)
-- Linear interpolation
linear :: Anim Duration
linear = (id, Nothing)
-- Sequencing
seq :: Anim a -> Anim b -> Anim (Either a b)
seq (f, Nothing) g = (\t -> Left $ f t, Nothing)
seq (f, Just df) (g, dg) =
(\t -> if t < df
then Left $ f t
else Right $ g t
, df + dg)
-- Parallelism
par :: Anim a -> Anim b -> Anim (a, b)
par (f, df) (g, dg) = (\t -> (f t, g t), max df dg)
-- Constant
pure :: a -> Anim a
pure a = (const a, Nothing)
-- EDIT: forgot delay
delay :: Duration -> Anim ()
delay d = (const (), d)
I know there's an Applicative in there, but I'm not sure where else this lies in the typeclass hierarchy.
EDIT: More fixes
EDIT: I should really test in GHCI before I post these things. But I'm lazy.