Animation as FRP: Fran, Yampa, Elm, Reflex (Haskell, Elm)
Functional reactive programming was invented to describe animation: Fran (1997) made an animation a value, Behavior a = a function of continuous time, so a tween is literally \t -> lerp a b (ease ((t - t0) / d)) and sampling is the runtime's business; its descendants keep the purity but move the clock to a driver (Yampa), to runtime messages (Elm), or to timer threads (Reflex).
| Field | Value |
|---|---|
| Language | Haskell (Fran, Yampa, dunai/Rhine, Reflex); Elm (compiles to JavaScript) |
| License | Yampa, dunai, Rhine, Reflex, reflex-dom: BSD-3-Clause; elm/browser, mgold/elm-animation, mdgriffith/elm-animator: BSD-3-Clause (each elm.json); Fran 1.16: a Microsoft Research download licence linked from the Fran home page |
| Repository | Fran: none (zip releases on conal.net/fran); ivanperez-keera/Yampa; ivanperez-keera/dunai; turion/rhine; elm/browser; mgold/elm-animation; mdgriffith/elm-animator; reflex-frp/reflex, reflex-frp/reflex-dom |
| Documentation | Elliott & Hudak, Functional Reactive Animation (author's page); Peterson, Elliott & Ling, Fran 1.1 Users Manual (1998-06-17); Elliott, Composing Reactive Animations; Courtney, Nilsson & Peterson, The Yampa Arcade (PDF); Elliott, Push-Pull Functional Reactive Programming (PDF); module docs of the sources below |
| Category | Animation as a pure value of time (Fran, elm-animation, elm-animator) or as a sampled signal function stepped by a host (Yampa, Rhine); time as a discrete event stream (Elm subscriptions, Reflex ticks) |
| Versions surveyed | Fran 1.16 (docs for 1.1, 1998); Yampa 0.15.1 at 9dda030 (2026-10-21); dunai 407ff00 (2026-10-21); Rhine 1.8 at 698b693 (2026-09-21); elm/browser 1.0.2 at 1d28cd6 (2019-11-06); legacy elm-lang/core 3.0.0 at 09f3dd2 (2015-11-22); mgold/elm-animation 2.0.0 at cb278e8 (2020-01-28); mdgriffith/elm-animator master (elm.json 2.0.0) at 12ca2ee (2026-09-25); Reflex at f443526 (2026-11-22); reflex-dom at de31cef (2026-11-23) |
| Animation state lives in | Fran: nowhere but the behaviour value (the runtime keeps only sampling state); Yampa: inside the running signal function (integrator accumulators in its continuation); Elm: in the Model, as an Animation record or a Timeline state; Reflex: in Dynamics held by the network (holdDyn/foldDyn) |
NOTE
This page covers four subjects, one ### section each under How it works, and compares them along the catalog's spine in Analysis. The reactive-programming catalog already describes each as a reactive runtime — Yampa, Elm, Reflex, the shared vocabulary and how each is tested — and those mechanics are not repeated here: this page is about what each one does with animation. The vocabulary (tween, closed form, retargeting) is the catalog's own concepts page.
Overview
What it solves
The problem Fran set out to remove is the gap between what an animation is and the frame loop that presents it. Elliott's tutorial states it:
"behaviors like motion and growth are generally gradual, continuous phenomena. Moreover, many such behaviors go on simultaneously. Computers, on the other hand, cannot directly accommodate either of these basic properties, because they do their work in discrete steps rather than continuously, and they only do one thing at a time. Graphics programmers have to spend much of their effort bridging the gap between what an animation is and how to present it on a computer." (Composing Reactive Animations)
Fran's answer is to make the animation a first-class value over continuous time and leave the frame loop to the library. The paper's abstract (author's page) names the two types and the claim that animation falls out of them:
"Behaviors are time-varying, reactive values, while events are sets of arbitrarily complex conditions, carrying possibly rich information. Most traditional values can be treated as behaviors, and when images are thus treated, they become animations."
Every later system on this page keeps one half of that and gives up the other. Yampa keeps continuous-time semantics and the physics (integrals, switching) but makes signal functions, not signals, the values, to remove Fran's leaks. Elm keeps the pure view and drops time as a value: time arrives as a message, and an animation is whatever the model stores. Reflex keeps first-class Behaviors but over discrete frames, and has no animation layer of its own.
Design philosophy
- Time is continuous; sampling is an implementation detail. The push-pull paper restates Fran's position: "Behaviors can change continuously (not just frequently), with discretization introduced automatically during rendering. The choice of continuous time makes programs simpler and more composable than the customary (for computer programming) choice of discrete time, just as is the case with continuous space for modeled imagery. For instance, vector and 3D graphics representations are inherently scalable (resolution-independent), as compared to bitmaps" (Push-Pull FRP §1). An animation written against
timedoes not know the frame rate. - The denotation is a function. "Semantically, a (reactive) behavior is just a function of time, while an event … is a list of time/value pairs", written
type B a = T → a(Push-Pull FRP §2). The Fran manual says the same operationally: "the type Behavior T is the same as Time -> T in that it maps time values onto values of type T" (manual). Lifting is pointwise:at (fmap f b) = f ∘ at b. - Describe what is, not what to do. "events and behaviors describe things that exist, rather than actions that have happened or are to happen (i.e., what is, not what does)" (Push-Pull FRP §2). The tutorial contrasts this with imperative code that must "explicitly simulate rate-based animation by making lots of little discrete steps, accumulating approximations" (tutorial).
- The driver owns the clock (Yampa). "Reactimate approximates the continuous-time model presented here by performing discrete sampling of the signal function, invoking sense at the start and actuate at the end of each time step" (The Yampa Arcade §3.6).
- Time is just another input (Elm).
elm/time'sTime.everycarries the warning "This function is not for animation. Use the [onAnimationFrame] function for that sort of thing! It syncs up with repaints" (Time.elm); the animation libraries then treat the frame timestamp as an argument: elm-animation'sanimate"takes the current time and an animation, and produces the current value" (README.md).
How it works
Fran
Behaviours, events, reactivity. A Behavior a is a value at every real time; time :: Behavior Time is the identity behaviour, and numeric classes are lifted so wiggle = sin (pi * time) oscillates with period 2 s. An Event a is "a time-sorted list of occurrences", [(Time, a)]. untilB :: GBehavior bv => bv -> Event bv -> bv "changes the course of a behavior when an event occurs"; switcher does so repeatedly; stepper builds a piecewise-constant behaviour from an event; snapshot :: Event a -> Behavior b -> Event (a, b) samples a behaviour at each occurrence (manual). Images are behaviours too: ImageB composes with over, move :: Vector2B -> ImageB -> ImageB, stretch :: RealB -> ImageB -> ImageB, withColor, so "when images are thus treated, they become animations".
A tween is a behaviour. Fran ships no tween combinator because none is needed; a tween is a lifted expression in time. As a sketch in the manual's vocabulary (untested — the 1.16 implementation runs on Hugs 98 under Windows and its author calls it stale on the home page):
-- the denotation of a tween: a pure function of time
tween :: Time -> DTime -> RealVal -> RealVal -> RealB
tween t0 d a b = lift1 f time
where f t = a + (b - a) * ease (clamp 0 1 ((t - t0) / d))
ease x = (1 - cos (pi * x)) / 2
clamp lo hi = max lo . min hi
panel u = move (vector2XY (tween 0 0.75 (-1) 1) 0) (stretch 0.2 (withColor red circle))Nothing is stored between frames: the runtime evaluates the behaviour at whatever instants it presents. Because the meaning is independent of the sampling instants, a 30 Hz and a 144 Hz presentation are samples of the same function.
Time transformation. timeTransform :: GBehavior bv => bv -> Behavior Time -> bv "yields a new behavior which is evaluated in a transformed time-frame", and later dt b = b `timeTransform` (time - dt), faster x b = b `timeTransform` (time * x) and slower x = faster (1/x) are defined from it (manual). The tutorial staggers a sentence along the mouse path with delayAnims dt anims = overs (zipWith later [0, dt ..] anims) (tutorial). The display routine itself is a time transform: userDelay bv u = later (constantB (userStartTime u)) bv, so every displayed animation starts at its own local time 0 (manual). Time transformation is how Fran composes in time, and it is only possible because a behaviour is a function, not a running process.
Physics by integration. integral :: (VectorSpace v) => Behavior v -> User -> Behavior v; integrals may be mutually recursive, and the bouncing ball accumulates collision impulses as an event sum (manual, example 11):
example11 u = withColor red (moveXY 0 pos (stretch 0.1 circle))
where
pos = p0 + integral vel u
vel = v0 + integral acc u + sumE impulse
impulse = collide `snapshot_` vel ==> (* (-1.9))
collide = predicate (pos <=* (-1) &&* vel <* 0) u
acc = -1
p0 = -1
v0 = 2This is where the resolution independence ends. The User argument "supplies the integration start time and a sampling clock which determines the step size used by the underlying numerical method", and predicate uses the same clock: "Care must be taken since sampling may miss occurrences of the boolean behavior", which is why the collision tests <=* rather than equality (manual). A closed-form behaviour (a tween) is exact at any sample; an integrated one (a spring, a fall) is only as good as the sampling clock the runtime supplies. The ICFP paper's interval-analysis event detection was the attempt to make predicate exact; the 1.1 manual records that "Some previous versions of Fran were able to detect even equality events".
Leaks, and what push-pull changed. A first-class behaviour denotes the whole history of a signal, so a late consumer (an integral started inside an untilB, a snapshot taken long after construction) can force the runtime to retain or recompute old samples. That is the space/time-leak story Yampa was designed to remove; it is told on the Yampa page. The push-pull paper names the cost for animation directly: sampling switcher "involves searching through an event for the last occurrence before t. This search becomes costlier as t increases, wasting time as well as space", and "in practice, behaviors are sampled with monotonically increasing times" (Push-Pull FRP §3). Its fix decomposes a behaviour into discrete phases (Reactive, pushed) and, within each phase, a time function (pulled):
data Reactive a = a `Stepper` Event a
data Fun t a = K a | Fun (t -> a)K marks a constant phase, so "Wherever phases are constant (a common case), sampling happens only once per phase, driven by occurrences of relevant events" (Push-Pull FRP §3). For animation this is the precise statement of "request frames only while something moves": a settled animation is a K phase and needs no samples.
Yampa
Signal functions, not signals. A program is one SF Input Output; integral and time are signal functions, not values of time (Yampa page). time = localTime = constant 1.0 >>> integral, which "Outputs the time passed since the signal function instance was started" (Time.hs), so a tween is an arr after localTime and restarts at 0 whenever it is switched in. integral is "Integration using the rectangle rule": each step adds dt *^ aPrev to the accumulator held in the next continuation (Integration.hs). imIntegral and trapezoidIntegral are the alternatives; derivative is "A very crude version of a derivative … Use at your own risk."
The bouncing ball. The library's own SDL example (MainBouncingBox.hs) is the arrowized form of Fran's example 11, with the collision as a switch rather than an impulse sum:
falling :: Double -> Double -> SF () (Double, Double)
falling y0 v0 = proc () -> do
vy <- (v0+) ^<< integral -< gravity
py <- (y0+) ^<< integral -< vy
returnA -< (py, vy)
bounce :: Double -> Double -> SF () (Double, Double)
bounce y vy = switch (falling y vy >>> (Yampa.identity &&& hitBottom))
(\(y, vy) -> bounce y (-vy))switch replaces the running falling with a fresh one started from the position and velocity carried by the event. That is retargeting in its most explicit form: the continuation receives (value, derivative) at the switching instant and starts a new motion from them (Switches.hs).
Space Invaders. The Yampa Arcade answered a public challenge that "getting an alien spaceship to move slowly downward, moving randomly to the left and right, and bouncing off the walls, turned out to be a major headache" in reactive animation (PDF §1). Its gun is a damped spring written as two integrals in a rec loop (PDF §4):
simpleGun (Point2 x0 y0) = proc gi -> do
(Point2 xd _) <- ptrPos -< gi
rec
-- Controller
let ad = 10 * (xd - x) - 5 * v
-- Physics
v <- integral -< clampAcc v ad
x <- (x0+) ^<< integral -< v
fire <- leftButtonPress -< gi
returnA -< SimpleGunState { sgsPos = (Point2 x y0), sgsVel = (vector2 v 0), sgsFired = fire }The pointer is the spring's target, so the target changes every frame and the motion stays smooth because (x, v) is the state: there is no separate retarget operation. The game objects (gun, aliens, missiles) form a dynamic collection under dpSwitch, whose killOrSpawn function "observes the output of the collection … and determines when signal functions are added to or removed from the collection" (PDF §5.1). A destroyed alien's signal function stops being stepped at once; an explosion would have to be a new object spawned in its place.
The driver owns the clock. reactimate init sense actuate sf loops: actuate the output, then sense False returns (dt, Maybe a) and the SF is stepped with that dt (Simulation.hs). The SF never reads a clock. The SDL example makes the ownership vivid: its yampaSDLTimeSense reads SDL.getTicks (milliseconds) and returns fromIntegral dt / 100 (YampaSDL.hs), so the "seconds" its physics integrate are tenths of a second and the whole simulation runs ten times faster than its constants say. Nothing inside the SF can notice. embedSynch runs an embedded SF "at a given (but variable) ratio >= 0 to the outer time flow. When the ratio is 0, the embedded signal function is paused" (Simulation.hs) — Fran's faster, available only as a driver-level rate.
dunai and Rhine make the clock a type. BearRiver's SF m = MSF (ClockInfo m) reads dt from a ReaderT (Yampa page § Related designs); Rhine's Clock class gives each signal function a clock with its own Time and Tag. FixedStep n is "A pure (side effect free) clock with fixed step size … The tick rate is in the type signature, which prevents composition of signals at different rates" (FixedStep.hs); GlossSimClockIO (Time = Seconds Float) blocks on the gloss backend's simulation ticks (Gloss/IO.hs). An animation's frame clock and a physics fixed step are then two clocks joined by a resampling buffer, checked at compile time.
Elm
Time is a message. Browser.Events.onAnimationFrame : (Time.Posix -> msg) -> Sub msg and onAnimationFrameDelta : (Float -> msg) -> Sub msg "hook into JavaScript's requestAnimationFrame function"; the delta variant gives "the time in milliseconds since the previous frame … nice for stepping animations by a time delta" (Events.elm). The effect manager behind them (AnimationManager.elm) holds one pending rAF process for all subscribers: when the subscription list becomes empty it Process.kills that process; on each frame it re-arms rAF and sends every tagger the new time, or newTime - oldTime for the delta form. The kernel's _Browser_rAF resolves with Date.now(), not with the timestamp requestAnimationFrame passes its callback (Browser.js), so Elm animations sample wall-clock milliseconds at callback time rather than the frame's vsync time. The view is batched separately: _Browser_makeAnimator draws at most once per animation frame however many messages arrive (Browser.js; Elm page).
The application therefore keeps the clock itself, in the model, as elm-animation's Retarget example does (Retarget.elm):
type alias Model =
{ clock : Clock
, x : Animation
, y : Animation
-- …
}
updateTick : Float -> Model -> Model
updateTick dt model =
let
clock = model.clock + (if model.slow then dt / 5 else dt)
-- …Holding shift divides every delta by five, slowing the whole scene: Fran's slower 5, done by the one function that owns the model's clock (Retarget.elm).
Before 0.17, time was a signal: Time.fps : number -> Signal Time gives "a sequence of time deltas as quickly as possible until it reaches the desired FPS", and fpsWhen adds a Signal Bool gate so "brief animations based on user input" run "without major inefficiencies"; "The first time delta after a pause is always zero, no matter how long the pause was" (legacy Time.elm). An animation was a foldp over that signal. 0.17 removed Signal (Elm page); the gate became subscriptions : Model -> Sub Msg returning onAnimationFrame only while something moves.
mgold/elm-animation: an animation is a record. An Animation is an opaque wrapper over (Animation.elm):
type alias AnimRecord =
{ start : Clock
, delay_ : TimeDelta
, dos : DurationOrSpeed
, ramp : Maybe Float -- used for interruptions
, ease_ : Float -> Float
, from_ : Value
, to_ : Value
}animate : Clock -> Animation -> Value is exactly the tween denotation: fr = clamp 0 1 ((clock - start - delay_) / duration_), from_ + (to_ - from_) * ease_ fr + correction (animate). The defaults are 750 ms and the sinusoidal (1 - cos (pi * x)) / 2; speed replaces the duration with an average rate. The README states the payoff: an animation is constant before its delay and after its end, and with static "you ought to be able to keep animations in your model without worrying about when they aren't actually animating" (README.md). Its doctest samples one value at seven times — List.map (\t -> animate t myAnim) [0, 1, 2, 3, 4, 5, 6] — which is a test with virtual time and no harness.
Retargeting keeps velocity. retarget : Clock -> Value -> Animation -> Animation "Change[s] the to value of a running animation, without an abrupt change in velocity … The animation will retain its average speed (but not necessarily duration)" (retarget). For a running animation it builds a new record starting now from the current position, with ramp = Just vel, where vel is getVelocity clock u, "aproximated by looking 10ms forwards and backwards (the central difference)" (getVelocity). animate adds the correction vel * (clock - start) * (1 - cosineEase fr), which starts with the old slope and fades out, so the curve is continuous in value and slope at the interruption. A scheduled animation just gets a new to; a finished one starts afresh from its old to. The Retarget example retargets x and y on every click and notes the consequence: "When retargeted, acceleration changes instantly but velocity does not" (Retarget.elm).
mdgriffith/elm-animator: a timeline of states. A Timeline state is "roughly a list of states and the times that they should occur" (Timeline.elm). The app stores one per animated concept (Timeline Bool for visibility), subscribes to onAnimationFrame only if Timeline.isRunning model.visible, and on each tick calls Timeline.update now (getting started). Timeline.to duration state is interrupt [ transitionTo duration state ]; interrupt replaces the pending schedule ("the latest nonempty schedule wins"), queue appends after the current one finishes, and wait inserts a pause (interrupt). Version 1.x spelled these Animator.go, Animator.interrupt, Animator.queue (changelog.md).
The view reads values by mapping states to targets, and the value is recomputed from the retained history every time it is read (Value.elm):
Animator.Value.float model.visible <|
\visible -> if visible then Animator.Value.to 1 else Animator.Value.to 0movement folds every retained transition up to the timeline's now (Timeline.foldpAll); an interrupted transition "contribute[s] [its] position and velocity at the interruption time" to the next. So the view is a pure function of the model, and now is part of the model, written by update (InternalAnim/Timeline.elm). update is forward-only — now = Quantity.max (Time.absolute possiblyNow) timeline.now, with the note "we can only move forward with updating … for something like debug mode, we might want to disable this to allow scrubbing" — and garbage-collects history older than maxDelay, five seconds, because "View functions may request any delay up to this duration after update has already run" (maxDelay). Curves are a Bézier (standard = cubic-bezier(0.4, 0, 0.2, 1)) or spring { wobble, quickness }, both in 0..1, whose "Duration still comes from the animation" (Transition.elm). The 2.0 rewrite also renders CSS transitions and keyframes directly (Animator.transition), which need no Elm clock at all (changelog.md).
Reflex
Reflex has no animation layer. Its Behavior t a is not Fran's: the denotational reference implementation defines newtype Behavior (Pure t) a = Behavior {unBehavior :: t -> a} but requires that "The 'Enum' instance of t must be dense" — time is a sequence of discrete frames (Reflex/Pure.hs), and "There is no clock in the core" (Reflex page). Wall-clock time enters as an event:
data TickInfo = TickInfo
{ _tickInfo_lastUTC :: UTCTime -- UTC time immediately after the last tick
, _tickInfo_n :: Integer -- ticks since the start of the timer
, _tickInfo_alreadyElapsed :: NominalDiffTime -- time elapsed in the current tick period
}
tickLossyFromPostBuildTime :: (…) => NominalDiffTime -> m (Event t TickInfo)tickLossyFromPostBuildTime dt reads the clock at post-build and then fires "approximately each time the provided interval elapses. If the system starts running behind, occurrences will be dropped rather than buffered"; each period is a forkIO thread that Concurrent.delays and triggers a frame (Reflex/Time.hs). An animated value is then user code: holdDyn the tick's _tickInfo_lastUTC into a Dynamic t UTCTime, hold the current animation record in another Dynamic (updated by attaching the current time to a retarget event), and zipDynWith a tween function over the two — the elm-animation shape rebuilt from Dynamics. The tick is a timer, not a vsync: nothing aligns it with the display, and it runs whether or not anything moves.
reflex-dom's only use of requestAnimationFrame is internal: DomRenderHookT, "Shared behavior for HydrationDomBuilderT and HydrationRunnerT", runs requested DOM updates inside DOM.inAnimationFrame' (Immediate.hs). The hydration test suite intercepts window.requestAnimationFrame (holdAnimationFrames/releaseAnimationFrames) because "DOM updates requested by the widget run in animation frames" (hydration.hs). No animation-frame Event, tween, spring or transition is exported by either repository at the surveyed revisions (searched for animat, AnimationFrame, tween, lerp).
Analysis
Where animation state lives
- Fran: in the value, not in a store. A tween is
tween t0 d a b; its parameters are captured by the behaviour, and the runtime keeps only what sampling needs (integrator state, the position reached in an event list). No identity-keyed state exists because none is needed: the behaviour is the animation. - Yampa: inside the running signal function.
integral's accumulator lives in the continuationSF'returned by each step (Integration.hs). It is invisible from outside except through what the SF outputs (the gun outputssgsVelso others can read it) or throughkSwitch's frozen continuation (Yampa page). - Elm: in the
Model. elm-animation storesAnimationrecords next to the domain data (x : Animation); elm-animator replaces a domain field withTimeline state(visible : Timeline Bool). Both are plain immutable values thatupdatereplaces andviewreads. - Reflex: in
Dynamics created byholdDyn/foldDyninside the widget that owns the animation, so lifetime follows the widget's subnetwork.
The common ground is that the stored thing is the animation description (start, from, to, curve), not the current value. Only the stepped integrators (Yampa's integral, Fran's integral behind its User clock) hold a current value.
Declaring an animation
All four are explicit: no value change animates by itself. In Fran and Yampa the animation is the program (a behaviour or signal function); the declarative target exists only as a lifted expression (move (tween …)) or as the target input of a controller (the gun's xd). Elm's libraries are declarative over a target state with an explicit trigger: elm-animator's Timeline.to (Animator.ms 300) True declares "go to True" and the view maps each state to a target value, which is the nearest thing in this family to implicit animation — the view says what each state looks like, and the timeline interpolates between whichever states it passes through. elm-animator 2.0's Animator.transition (Animator.ms 200) [ Animator.opacity … ] is implicit, but only because it compiles to a CSS transition and hands the animation to the browser (README.md). Reflex has nothing to declare.
None has an imperative controller object with start/stop methods. "Starting" is constructing a value (animation now |> to 300) or switching one in; "stopping" is replacing it.
Time and the clock
| System | Time model | Who owns the clock | What an animation sees |
|---|---|---|---|
| Fran | continuous, absolute; timeTransform re-maps it | the display runtime (displayU, userDelay); User supplies sampling | time, shifted to local 0 by userDelay |
| Yampa / Rhine | continuous semantics, sampled by dt | the reactimate driver's sense; Rhine: a typed Clock | localTime, restarting at each switch-in |
| Elm | discrete messages carrying Time.Posix or a delta (ms) | the runtime's rAF effect manager; the app accumulates its own clock | whatever Clock the model passes to animate |
| Reflex | discrete frames; wall time as TickInfo events | a forkIO timer thread per tickLossy | a Dynamic t UTCTime the app holds |
Fran and elm-animation agree on the one thing that matters for purity: an animation is evaluated at a time given to it, never by reading a clock. Fran's runtime picks the instants; Elm's app picks them (and can scale them, as the Retarget example's slow-motion does). Yampa inverts this: the SF is given dt, not t, so any absolute time is an integral the SF computes. That makes Yampa's driver more powerful (it can scale, pause or replay time) but makes a tween stepped state rather than a closed form. Neither Elm nor Reflex aligns animation to the frame's presentation time: Elm samples Date.now() in the callback (Browser.js); Reflex's ticks are not frames at all.
Interruption and retargeting
Interruption in FRP is switching, and retargeting is switching to a new behaviour that starts from the old one's current value and derivative.
- Fran:
untilB/switcherto a behaviour built from asnapshotof the current position and velocity (velocity is available when the motion is defined byintegral, as in example 11). Nothing does this automatically; a switch to a plain tween from the snapshot keeps the value and loses the slope. - Yampa:
switch's continuation receives whatever the event carries; the bouncing ball passes(y, vy)and negatesvy(MainBouncingBox.hs). A spring-shaped controller (the gun) needs no switch: its target is an input, and(x, v)continuity is automatic because they are the integrator state. - elm-animation:
retargetkeeps value and (numerically estimated) velocity and keeps the average speed; the duration changes with the distance (retarget).undoreverses from the current state. Multi-axis motion must retarget every axis with a syncedduration, or the axes arrive at different times (the example's comment: "sync durations, very important"). - elm-animator:
interruptalways continues from the sampled position; velocity is continuous only forspringtransitions, whoseSpring.attakes the incoming velocity as its initial condition (InternalAnim/Transition.elmatX) — the test "A spring interruption preserves incoming velocity at the interruption instant" checks{ position = 100, velocity = 200 }(Values.elm). A Bézier transition's velocity comes from the new curve alone, so a linear interruption has a kink. The changelog says so: "use timeline springs for velocity-preserving interruptions" (changelog.md). - Reflex: whatever the user's tween function does.
None of the four composes animations additively (summing several in-flight contributions on one value), although Fran's lifted + makes tween … + tween … trivially expressible.
Curves and springs
- Duration and easing are a user-supplied
Float -> Floatin elm-animation (default sinusoid,f 0 == 0andf 1 == 1expected) and a Bézier or linearTransitionin elm-animator. Fran and Yampa have no easing library; an easing is any lifted function oftime/localTime. - Springs as physics are integrals in Fran and Yampa: the gun's
ad = 10 * (xd - x) - 5 * vis stiffness 10 and damping 5 (damping ratio5 / (2 * sqrt 10)≈ 0.79, slightly underdamped), stepped by the rectangle rule (PDF §4,Integration.hs). The result depends on the step: Fran's manual puts the step size in theUsersampling clock, and the SDL driver's/ 100changes what the constants mean. - Springs in closed form are elm-animator's:
spring { wobble, quickness }in0..1, evaluated bySpring.atat an elapsed time with no stepping, and fitted to the transition's duration (settleMax = totalDuration) (atX,Transition.elm). A closed-form spring keepsvalue(now)a pure function and can be sampled at any instant; a stepped one cannot (concepts).
Layout animation
Not applicable in any of the four as a layout mechanism, because none has a layout engine that animation participates in:
- Fran animates geometry as image transforms:
move,stretchand the 3Dturn3are behaviours composed into theImageB, applied when the image is rendered — the paint/compose phase. There is no layout; positions are coordinates the program computes. - Yampa has no presentation layer; the actuator renders whatever numbers the SF outputs.
- Elm computes geometry in user code (
update/view) and emits it as attributes or styles; the browser lays out. Reading the previous frame's layout is an effect:Browser.Dom.getElement : String -> Task Error Elementcalls_Browser_withNode, which waits onerequestAnimationFramebefore readinggetBoundingClientRect()(Browser.js,Dom.elm). The rect arrives as a message in a laterupdate, so a FLIP-style layout animation in Elm is: render, read the committed rect, store(oldRect, newRect)in the model, animate a transform from the difference. That is user code driven by last frame's geometry — the shape UI-Q9 (PR #775) asks about — with the read deferred by one frame and the animation applied as a paint-time transform. - Reflex (reflex-dom) builds a retained DOM; geometry readback is a JavaScript FFI call outside the libraries surveyed.
Enter and exit
None of the four has an exit mechanism; absence is the model's business.
- In Fran, an image that should fade out is
fadingImage `untilB` (doneE -=> emptyImage): the program keeps it present until its own event says it is gone. The element is never "removed while painting"; it is present until its behaviour becomesemptyImage. - In Yampa,
dpSwitch'skillOrSpawnremoves a signal function at an instant; anything that should outlive the kill (an explosion) is spawned as a separate object in the same switch (PDF §5). - In Elm, a list item that should animate out stays in the model with a "leaving" timeline (
Timeline Boolgoing toFalse), and the app deletes it whenTimeline.arrivedAtreports the end, or when an elm-animation recordisDone. The view stops building it only after that. - Reflex's
listWithKey/networkHoldtear a widget's subnetwork down when its key disappears, taking itsDynamics with it.
This is the "closing state the store drives" answer to UI-Q10 (PR #775): the item is still built, from state that says it is closing, until the animation that state carries is done.
Scheduling, reduced motion and testing
Request frames only while animating. Elm gets this from subscriptions being a function of the model: elm-animator's documented setup subscribes if Timeline.isRunning model.visible, and AnimationManager kills its pending rAF process when no subscription remains (getting started, AnimationManager.elm). Legacy Elm had the same as fpsWhen. elm-animation exposes isDone/timeRemaining for the app to gate on; its own Retarget example subscribes unconditionally (Retarget.elm). Push-pull FRP gives the semantic version: constant K phases are sampled once (Push-Pull FRP). Yampa's driver must keep ticking because an SF cannot report its next deadline (Yampa page); Reflex's tick thread runs until its widget is torn down.
Reduced motion is handled by none of them. Nothing in elm/browser, elm-animation, elm-animator or reflex-dom reads prefers-reduced-motion (searched at the surveyed revisions); an Elm app would pass matchMedia through flags or a port. Fran's timeTransform shows the shape such a preference could take in a pure system: a transform of the time an animation is evaluated at (faster toward infinity jumps to the end state), applied once at the root.
Testing. Pure time makes tests trivial wherever an animation is a value:
- elm-animation's README doctest samples
animate t myAnimover a list of times (README.md). - elm-animator's tests drive
Timeline.update (Time.millisToPosix 10500)and assertValue.float/Value.movement, including fuzzed interruptions checked against an independent two-segment model (Values.elm). The forward-onlyupdatemeans a test cannot rewind a timeline; it must rebuild one. - Yampa's
embedruns an SF over(dt, Maybe input)samples, and a bouncing ball is a list of heights (Yampa testing). - elm-program-test simulates
Process.sleepwithadvanceTimebut has no animation-frame simulation (noAnimationFramein its source); a test sends theTickmessage itself (Elm testing). - Reflex has no virtual time;
tickLossysleeps for real (Reflex page).
Lessons for sparkles:ui
- Store the animation, not its value. An element-store entry shaped like elm-animation's
AnimRecord—(start, from, to, spec)plus the initial velocity for a retarget — lets a@safe pure nothrow @nogccomponent computevalue(now)from last frame's committed store and the frame'snow, bothconstinputs. That is Fran's denotation with the store standing in for the closure. The component never writes the record; it yields a message (or the host derives the change), and the host commits the new record after layout, as UI-Q5 already requires. - Retarget analytically from the old record. A retarget is a new record whose
fromisold.value(now)and whose initial velocity isold.velocity(now). elm-animation estimates velocity by a ±10 ms central difference; a closed-form curve (and a closed-form spring, as in elm-animator andsparkles:ui'sScrollMotion, baseline) can return its exact derivative. Springs should be closed-form so a spring is also plain data and the view stays pure; Yampa's rectangle-ruleintegraland the SDL driver's/ 100show how stepped physics ties meaning to the frame source. - The host owns one clock, and passes
now. Every system here that keeps the view pure gets time as an argument. Onenowper frame (preferablyFrameStart.target) given to every component removes Elm's "the app accumulates deltas in the model" step and theDate.now()-at-callback skew. A time transform at the root (Fran'sfaster, theRetargetexample's slow-motion, elm-animator'sscale) is then the place for slow-motion debugging and for reduced motion. - "Still running" and "next deadline" come from the records. Given
now, the store can answer whether any record is not yet done and when the next one ends — elm-animator'sisRunning, push-pull's constant phases — which is whatrequestFrameandwakeInneed. Yampa's lack of a deadline query is the failure mode to avoid. - Exit is a closing state in the store (UI-Q10). None of these systems retains a snapshot of a removed element; each keeps it present while its state says it is leaving (Fran's
untilBtoemptyImage, Elm's "leaving" timeline, Yampa's spawned explosion). Forsparkles:ui, where presence is "built this frame", the analogue is a store entry that outlives the identity's last build until its exit record is done, with the host continuing to paint it from that record. - Layout animation needs last frame's geometry as data (UI-Q9). Elm's
getElementdelivers the committed rect one frame later as a message; the animation is then a transform from(oldRect, newRect)applied at paint. Insparkles:uithe previous rect is already in the store, so the same animation can be computed in user code from committed geometry and applied as a paint-time offset, without layout re-running per frame. - Keep evaluation seekable. elm-animator's forward-only
updateand five-second history window exist to bound a fold over retained history. A record-per-identity store needs no history, sovalue(t)can be sampled at anyt— which is what makes a recorder-driven test (sample the view at a list of times, asembeddoes) possible.
Strengths
- One denotation for every animation.
Time -> aexplains tweens, delays (later), speed changes (faster) and composition in time without any runtime concept; Fran's time transforms fall out of it. - Purity of the view. Fran, elm-animation and elm-animator keep the animated view a pure function of
(model, time); tests are lists of times. - Physics as equations. Fran's and Yampa's integrals let a spring or fall be written as its differential equation, and Yampa's gun shows target-tracking with no retarget operation at all.
- Retargeting with velocity continuity is a library function in elm-animation and a property of springs in elm-animator, both over immutable values.
- State-driven frame scheduling in Elm:
subscriptionsandisRunningmake "only tick while moving" a pure function of the model.
Weaknesses
- Continuous time is not free. Integrals and predicates need a sampling clock (Fran's
User, Yampa'sdt), so physics is exactly as resolution-dependent as a hand-written loop. - Leaks or plumbing. First-class behaviours leak history (Fran); removing them forces arrow plumbing and makes a tween stepped state (Yampa).
- No presentation-time clock. Elm samples
Date.now()in therAFcallback; Reflex uses timer threads; Yampa takes whateverdtthe driver measures. - No exit, layout or reduced-motion support in any of the four; each is left to the application.
- Reflex has no animation story beyond lossy wall-clock ticks.
- elm-animator's value is a fold over history, bounded by a forward-only clock and a 5 s retention window.
Key design decisions and trade-offs
| Decision | Rationale | Trade-off |
|---|---|---|
Behavior a = function of continuous time (Fran) | Resolution independence in time; composition in time via timeTransform | History retention (space/time leaks); integrals and events still need a sampling clock |
Signals not first-class; dt from the driver (Yampa) | Leak-free, causal, deterministic under embed | Absolute time is an integral; tweens become stepped state; driver can silently rescale time |
Retarget by switching with (value, derivative) | Interruption is ordinary control flow; any curve can follow any other | Continuity is the programmer's job unless the motion is a controller over integrator state |
| Time as a message; animation as a record in the model (Elm) | No runtime concept of animation; view stays pure; app can scale its own clock | App accumulates deltas itself; samples Date.now(), not the frame's vsync time |
retarget with a numeric velocity ramp (elm-animation) | Smooth retargeting of any easing over plain data | Velocity by central difference; average speed kept, duration changes; axes need syncing |
| Timeline of states, value folded from history (elm-animator) | Interruptions compose; springs carry velocity across them | Forward-only clock; 5 s retention; Bézier interruptions are not velocity-continuous |
Gate frames by subscriptions model (Elm) | Idle costs nothing; lifetime is a function of state | Every animation library must expose a "running" predicate for the app to gate on |
No animation layer; ticks via forkIO timers (Reflex) | Time stays outside the deterministic core | No vsync alignment, no virtual time, no tween or spring vocabulary |
Sources
- Elliott & Hudak, Functional Reactive Animation, ICFP 1997 (author's page, abstract quoted from it)
- Peterson, Elliott & Ling, Fran 1.1 Users Manual, 1998-06-17; Elliott, Composing Reactive Animations, 1998; Fran home page
- Elliott, Push-Pull Functional Reactive Programming, Haskell Symposium 2009-09-03 (author's page, PDF)
- Courtney, Nilsson & Peterson, The Yampa Arcade, Haskell Workshop 2003-08-28 (PDF)
- Yampa at
9dda03030c4edfdda6e908f49b5a92d1dda5c8a3:Integration.hs,Time.hs,Simulation.hs,Switches.hs,MainBouncingBox.hs,YampaSDL.hs - Rhine at
698b69397ec7d9545cdc9ae48967f970d42e2c28:FixedStep.hs,Gloss/IO.hs elm/browserat1d28cd625b3ce07be6dfad51660bea6de2c905f2:Events.elm,AnimationManager.elm,Dom.elm,Elm/Kernel/Browser.js;elm/timeTime.elm; legacyelm-lang/core3.0.0Time.elmmgold/elm-animationatcb278e818777ff19714aaa57d97f4f121acba815:README.md,Animation.elm,examples/Retarget.elmmdgriffith/elm-animatorat12ca2ee7eba6af39bf8a4b75a6845db2f5d6ec70:README.md,changelog.md,Animator/Timeline.elm,Animator/Value.elm,Animator/Transition.elm,InternalAnim/Timeline.elm,InternalAnim/Transition.elm,tests/Values.elm- Reflex at
f443526bd2a9d4ba43f65f3a755d21e61082f4e0:Reflex/Time.hs,Reflex/Pure.hs; reflex-dom atde31ceff3d995381da661dc25b50e5b99fdd6316:Immediate.hs,test/hydration.hs - Related pages: Yampa · Elm · Reflex · reactive concepts · testing FRP · animation concepts · sparkles baseline · UI authoring decisions · Manim