Skip to content

Yampa (Haskell) ​

The reference arrowized FRP library: a program is one signal function SF a b, built from arrow combinators and switches and stepped by an external driver with an explicit time delta. Signals are never first-class values.

FieldValue
LanguageHaskell (GHC 7.6.3 to 9.x; MicroHs since 0.15.1)
LicenseBSD-3-Clause (yampa/LICENSE, Yampa.cabal)
Repositoryivanperez-keera/Yampa, surveyed at 9dda030 (2026-10-21). Relatives: ivanperez-keera/dunai at 407ff00 (2026-10-21), turion/rhine at 698b693 (2026-09-21)
DocumentationHackage: Yampa, Haskell wiki, the module headers of FRP.Yampa
CategoryArrowized FRP (AFRP): synchronous dataflow over sampled continuous and discrete time
Versions surveyedYampa 0.15.1 (2026-10-21), dunai 0.14.2 / bearriver 0.15.1, rhine 1.8
Core abstractionSF a b, a signal function: conceptually Signal a -> Signal b, operationally a Mealy machine that takes (DTime, a) and returns (b, next SF)
LineageFran (1997), then FRP Continued / AFRP (2002), then Yampa, then dunai/BearRiver (monadic stream functions, 2016), then Rhine (type-level clocks, 2018). See Related designs

NOTE

Yampa has no notion of asynchrony, no scheduler, and no I/O inside a signal function. Every spine section below that asks about threads, cancellation or errors gets the answer "outside, in the driver". That absence is the main finding. Yampa is the cleanest model in the survey of a frame-ticked reactive core, and it shows how much of the worked pipeline still has to live outside such a core.


Overview ​

What it solves ​

Yampa programs hybrid systems: games, robots, synthesizers, simulations, where continuously varying quantities (positions, integrals, time) mix with discrete occurrences (clicks, collisions, messages). The module header of FRP.Yampa states the division of labour:

"A Yampa network is structured as a Signal Function: a pure transformation from a time-varying input to that produces a time-varying output. … The first two aspects [obtaining inputs, consuming outputs] lie outside Yampa, and they determine the backends that your system uses. Yampa is backend-agnostic."

The user writes one pure SF Input Output. A backend (SDL, GLFW, Gloss, HTML canvas, Android/iOS through Keera Studios' commercial games, per README.md) senses input once per frame, steps the SF with the frame's dt, and actuates the output. That is the same shape as a sparkles app's frame loop.

Design philosophy ​

The defining decision dates from Functional Reactive Programming, Continued (Nilsson, Courtney, Peterson, Haskell Workshop 2002), which recast Fran's first-class behaviours as arrows:

"In order to ensure an efficient implementation (one that is free of time and space leaks), signals (time-varying values) are not first class entities in AFRP, unlike the signal functions operating on them. This is one of the most substantial design differences between AFRP and earlier versions of FRP, for example Fran. … this design carries with it an apparent loss in expressive power … Continuation-based switching and dynamic collections of signal functions give AFRP similar expressive power, but without compromising operational aspects."

And, from the same paper:

"We reiterate that this is just a conceptual model: only signal functions are first class entities; signals only exist indirectly, through the signal functions. In particular, there is no type Signal in AFRP."

A first-class Behavior a in Fran could be held by any closure, and it denoted the whole history of a signal, so a late consumer could demand old samples and the runtime had to keep them (a space leak) or recompute them (a time leak). A signal function is causal and only ever sees the current sample. History it needs is state inside it. Nothing outside can retain a signal, so nothing outside can leak one. The library has guarded this property since 2003 with a dedicated long-running test, yampa-test/tests/Space.hs, which runs arr, loop, rSwitch, pSwitch, rpSwitch and accum for two million steps and asks the tester to "Observe the process size using some tool like top. The process should not grow significantly."


How it works ​

The real representation is in FRP.Yampa.InternalCore, a module hidden unless the package is built with the unsupported expose-core flag (Yampa.cabal):

haskell
type Time  = Double      -- [s]
type DTime = Double      -- [s]

data SF a b = SF {sfTF :: a -> Transition a b}       -- not yet started: no dt at time 0

data SF' a b where                                   -- running ("future") signal function
  SFArr   :: !(DTime -> a -> Transition a b) -> !(FunDesc a b) -> SF' a b
  SFSScan :: !(DTime -> a -> Transition a b) -> !(c -> a -> Maybe (c, b)) -> !c -> b -> SF' a b
  SFEP    :: !(DTime -> Event a -> Transition (Event a) b) -> !(c -> a -> (c, b, b)) -> !c -> b -> SF' (Event a) b
  SFCpAXA :: !(DTime -> a -> Transition a d) -> !(FunDesc a b) -> !(SF' b c) -> !(FunDesc c d) -> SF' a d
  SF'     :: !(DTime -> a -> Transition a b) -> SF' a b

type Transition a b = (SF' a b, b)                   -- next state, current output

Three points matter for a D port:

  1. It is a Mealy machine in continuation encoding. A step returns the output and the next machine. State lives in closures captured by that next machine, so each step that changes state allocates a new closure. FRP Continued §4 explains why streams were dropped for this: "It does not seem to be possible to implement first-class signal function continuations in a stream-based implementation, since the connection between a signal function and its input stream is hidden in a closure."
  2. Time zero is a different type. SF is the unstarted machine (no dt exists yet). SF' is the running one. A switch "starts" its continuation by calling sfTF without a dt. That is why localTime restarts at 0 inside a switched-in SF (Time.hs).
  3. Constructors carry optimisation hints. FunDesc (FDI identity, FDC constant, FDE event function, FDG general) lets fdComp, fdPar and fdFanOut fold stateless pipelines at run time: arr f >>> arr g becomes one FDG (g . f), and switchAux (SFArr _ (FDC (b, NoEvent))) collapses a switch whose trigger is constantly NoEvent into sfConst b. This is the subject of Nilsson's Dynamic Optimization for Functional Reactive Programming using Generalized Algebraic Data Types (2005, listed in the README). A D implementation gets the same effect statically from template specialisation.

The arrow instances supply composition (>>>, from Category), first/second, parallel ***, fan-out &&&, ArrowChoice (+++, so proc can case) and ArrowLoop (loop). Yampa also has Functor and Applicative instances: f <*> x = (f &&& x) >>> arr (uncurry ($)). So the README's three styles (arrow notation, applicative, raw combinators) are interchangeable:

haskell
signalFunction :: SF Double Double
signalFunction = proc x -> do
  y <- integral -< x
  t <- time     -< ()
  returnA -< y / t

signalFunction1 = (/) <$> integral <*> time          -- applicative
signalFunction2 = (integral &&& time) >>^ (/)          -- combinators

In proc notation the names x, y, t stand for the current sample, not for signals (FRP Continued: "Paterson's syntactic sugar for arrows effectively allows signals to be named"). The expression to the left of -< must not mention them, which keeps the network static between switches.

Events are an option-per-sample: data Event a = NoEvent | Event a (Event.hs), "isomorphic to Maybe" but carrying the promise that occurrences are sparse. A discrete stream is therefore just a continuous signal of type Event a, so one SF type covers both worlds. hold/accumHold (Hybrid.hs) go from events to continuous values, and edge/edgeBy (EventS.hs) go back.

Driving. Simulation.hs has two drivers. reactimate owns the main loop:

haskell
reactimate :: Monad m
           => m a                          -- ^ Initialization action
           -> (Bool -> m (DTime, Maybe a)) -- ^ Input sensing action
           -> (Bool -> b -> m Bool)        -- ^ Actuation (output processing) action
           -> SF a b                       -- ^ Signal function
           -> m ()

sense returns the elapsed dt and optionally a new input. Nothing means "same as last sample". actuate returns True to stop. reactInit/react invert control for hosts (GLUT, Gtk) that own the loop: react rh (dt, ma) does one step against an IORef-held state. embed is the pure version for tests.


Evaluation model ​

  • Synchronous, sampled, driver-pulled. One react step evaluates the whole network once, in the order composition fixes. Nothing propagates between steps and nothing runs without a step. This is the synchronous-dataflow hypothesis of Lustre and Esterel (the paper calls AFRP "a powerful synchronous dataflow programming language"), with continuous time approximated by the sampling.
  • Glitch-free by construction. Within a step every combinator sees exactly one value per input, computed earlier in the same step. There is no dependency graph to propagate through and no diamond problem. &&& simply evaluates both branches on the same sample.
  • Neither push nor pull in the Rx sense. Inputs are not pushed per occurrence: an Event is sampled, and two clicks inside one frame are one Event (or lost) unless the driver batches them into Event [Click]. Outputs are not pulled lazily per consumer. Every step computes every output, although Haskell laziness means unused fields are never forced. reactimate seqs a and b on each loop iteration to bound thunk chains.
  • Hot/cold does not apply. An SF is a pure, reusable description (cold). Each reactimate/embed/switch-start instantiates fresh state. There is no shared running instance to subscribe to, so no multicast question arises (State and sharing).
  • Instantaneous feedback must be broken by a delay (iPre, dSwitch, loopPre) or the step diverges at run time. Lazy evaluation lets loop type-check without forcing well-foundedness, and nothing checks it statically.

Composition ​

The operator surface is the arrow class plus about 135 export-list entries in FRP.Yampa. The module groups are basic SFs, event sources, pointwise event functions, switching, hybrid (hold/accumulate), delays, conditional, loops/integration, noise, simulation and tasks. The only genuinely stateful primitives are a handful (iPre, integral, sscan, hold-via-epPrim, edgeBy, the switches, afterEachCat, delay). Everything else is defined from them. For example, fby is b0 --> sf >>> pre, localTime is constant 1.0 >>> integral, and after q x is afterEach [(q, x)].

Derived values are plain composition: a "computed" signal is arr f after a fan-out, so there is no separate computed/map concept. The arrowized style forces every intermediate value to be named in proc or plumbed through tuples. Users accept this for games (tens of signals) but it scales poorly to UIs with hundreds of fields.

The switching family is how structure changes. Its header in Switches.hs doubles as a naming grammar:

CombinatorWho supplies the triggerWhat replaces whatInstant of switch
switch sf ksf itself: SF a (b, Event c)k c :: SF a b replaces sf, oncek c produces this output
dSwitch sf ksamesamesf's output kept; k c next
rSwitch sfthe input: SF (a, Event (SF a b)) beach event carries a fresh SF; latest wins, repeatedlyimmediate
drSwitch sfthe inputsamedecoupled
kSwitch sf e ka separate observer SF (a, b) (Event c)k (frozen sf) c: the continuation receives the running sf, state intactimmediate
dkSwitchsamesamedecoupled
pSwitch r sfs e kobserver of input + all outputsk (frozen collection) d: add, remove, reorder running SFsimmediate
rpSwitch r sfsinput events of col (SF) -> col (SF)each event mutates the live collectionimmediate
dpSwitch/drpSwitchas aboveas abovedecoupled
…B/…Z/parCrouting: broadcast, zip with list, replicate––

Analysed against the survey's concerns:

  • switch is one-shot structural lifetime. The old SF is dropped, which is all cancellation is for a pure machine: its state becomes garbage. rSwitch is that repeated, and it is the arrowized form of latest-wins (switchMap/flatMapLatest in RxJS or Kotlin Flow). A new inner SF arrives on an input event, the previous one stops being stepped, and the new one starts at local time 0. rSwitch sf = switch (first sf) ((noEventSnd >=-) . rSwitch). The noEventSnd >=- masks the triggering event from the new instance's first sample, so it cannot immediately re-switch.
  • d (decoupled) exists for feedback. In switch, the output at the switching instant comes from the new SF, so the output depends instantaneously on the trigger. If the trigger is computed from that output (through loop), the step diverges. dSwitch emits the old SF's output at that instant. The header warns: "If you use the same SF that originally provoked the switch, you are very likely to fall into an infinite loop. In those cases, the use of dSwitch or --> may help." For a D Cell, the analogous question is whether a write made during frame n is visible to readers in frame n or n+1.
  • k (continuation) switches turn running state back into values. kSwitch hands freeze sf1 dt (an SF built from the running SF' with the current dt baked in) to the continuation. The continuation can resume, discard, store or wrap it. FRP Continued calls this "the ability to 'freeze' running signal functions, turning them back into first class values (with preserved state, of course)", and its tailgating-detector example uses rpSwitch to add and remove per-car trackers without resetting the others. This is what Yampa offers instead of Fran's dynamic collections of signals. It needs a value-semantics copy of a running machine. In D that is a struct move, not a closure capture.
  • p (parallel) switches are keyed dynamic collections. The routing function is rank-2 (forall sf . a -> col sf -> col (b, sf)), so routing cannot inspect or duplicate the running SFs. The paper notes this gives them "second class status", while the continuation sees them frozen and first-class. That split (opaque while running, manipulable at a switch point) is a clean model for a keyed ForEach/list-of-tasks node.

API structure and naming ​

Source, transform and sink are one type. There is no separate source or sink type. A source is an SF a b that ignores its input: constant, time, never, now, after, repeatedly, afterEach, noise (EventS.hs). A transform is any SF. Sinks do not exist inside the language. The driver's actuate callback is the only sink, and embed (returning [b]) is the test sink. Everything composes with the same >>>. Yampa is all transform: a closed network whose two open ends are owned by the host.

Organisation. There is one prelude module, FRP.Yampa, that re-exports everything plus Control.Arrow. Sub-modules split by concept: Basic, Event (pointwise functions on event values: tag, merge, filterE, gate), EventS (signal functions producing events: edge, after, once), Hybrid, Delays, Switches, Simulation, Task. The Event/EventS split (value-level vs signal-level, distinguished by one trailing S) recurs in dunai (arrM vs liftTransS) and is easy to misread. Operators are free functions and infix symbols. A Haskell type has no methods.

Variant families are prefix and suffix letters, documented as a grammar. The Switches.hs header:

"Switches vary depending on a number of criteria: … /Decoupled/ vs normal switching /(d)/ … How the switching event is provided /( /r/k)/ … How many SFs are being handled /( /p/par)/ … How the input is router /(B/Z/ )/ … These gives a number of different combinations, some of which make no sense, and also helps determine the expected behaviour of a combinator by looking at its name. For example, 'drpSwitchB' is the decoupled (/d/), recurrent (/r/), parallel (/p/) switch with broadcasting (/B/)."

The same letters appear elsewhere. A d prefix means "one sample later": dHold, dAccumHold, dTrackAndHold, dSwitch. An i prefix means "initialised with a value": iPre, iEdge. Suffixes: By takes a function (edgeBy, accumBy, mergeBy), Cat catenates simultaneous occurrences into a list (afterEachCat, delayEventCat), E marks pointwise event functions (filterE, mapFilterE, joinE, splitE), and T marks the Task monad (constT, sleepT, snapT). Initialisation operators are symbolic: --> (replace first output), -:> (prepend an output), >-- (replace first input), -=> / >=- (map first output/input). Legibility depends on the reader. The grammar is learnable and stated in the source, but it yields 22 switch names (switch … drpSwitchZ, parC), and the four initialisation symbols cannot be guessed from their glyphs. The hand-maintained grammar suggests that a language with keyword or template parameters should make these axes parameters, not letters.

User-defined operators. A user cannot write a primitive. SF's constructor lives in the hidden InternalCore, and Time.hs says "If you really, really, really need to know the time delta, and need to abandon the hybrid/FRP abstraction, see iterFrom". A new stateful operator is written by composing the stateful kernels: sscan (pure fold, Scan.hs), loopPre (well-defined feedback through iPre, Loop.hs), localTime, edgeBy, hold, and switches. The worked pipeline's debounce is such a composite. Keeping the step function sealed is how the library preserves the leak-freedom and causality invariants.

Regrets and renames. The CHANGELOG records 0.13 (2018-11-02): "Clean API, remove deprecated constructs, move vector and point into separate library, hide Core. Eliminate Forceable and MergeableRecord." 0.15 (2025-02-27): "Deprecate FRP.Yampa.Arrow.arr3,arr4,arr5", now marked {-# DEPRECATED arr3 … #-} in Arrow.hs. Rhine's history is far more turbulent (see Related designs): SyncSF renamed to ClSF "and many other renames" in 0.5, the Schedule type deleted in 1.0, the dunai MSF replaced by Automaton in 1.3 (with iPre renamed delay and morphS renamed hoistS), and the SN GADT turned into a newtype in 1.6.

Time and scheduling ​

  • One clock, given as dt per step. Time is the sum of the dts the driver passes. There is no scheduler, timer queue or wall clock inside Yampa. localTime = constant 1.0 >>> integral, and Time.hs notes that "the SF switched into will be started at the time of switching". Switching therefore also resets local clocks, which is exactly what a restart-on-keystroke debounce wants.
  • Timed operators accumulate dt and compare. afterEachCat stores t as a negative offset, adds each dt, and fires when t' >= 0 (EventS.hs). delay keeps a sample queue with per-sample dts (Delays.hs). Firing is therefore quantised to the frame. An event is emitted "at or as soon after (local) time q as possible" (after's doc), and repeatedly explicitly avoids an "event backlog": at most one occurrence per sample.
  • No debounce. Yampa ships neither debounce nor throttle. The idiomatic form is restart-by-switch: on each change event, rSwitch into a fresh after n (local time 0). Because after's duration is a construction-time constant, a runtime-adjustable N needs the duration read from the input signal each sample. The worked pipeline does this with localTime plus a comparison, so changing N takes effect on the next sample, including firing immediately if N shrinks below the elapsed time.
  • No "next deadline". Nothing in the SF can tell the driver when the next timed event is due. A host that wants to sleep while idle (sparkles' wakeIn) cannot ask Yampa. It must keep ticking at frame rate, or know from outside that a debounce is pending. reactimate's sense takes a Bool "can block" argument, but the library always passes False (sense False in the loop). A D design should give time-based operators a nextDeadline query, which this model lacks.
  • Multi-rate is out of scope apart from embedSynch, which runs an embedded SF at a variable ratio to outer time (0 pauses it). Multi-rate is Rhine's whole reason to exist.

Concurrency and cancellation ​

Not applicable inside Yampa, and that absence is the design. An SF is pure. It cannot fork, block, perform I/O or observe another thread. Consequences:

  • Latest-wins over signal functions is rSwitch, and "cancellation" is ceasing to step the old SF. It is immediate and complete, and there is nothing to wait for, because the old machine has no running computation outside the step.
  • Latest-wins over work (the hash) is a protocol between the SF and the driver. The SF emits a command event (StartHash q, CancelHash). The actuator, in IO, cancels the previous worker and spawns a new one, and sense feeds the result back as an Event. Whether a cancel waits depends on the I/O library the actuator uses. With async's cancel, it does: "Cancel an asynchronous action by throwing the AsyncCancelled exception to it, and waiting for the Async thread to quit." That wait happens on the UI thread inside actuate. GHC delivers asynchronous exceptions only at allocation points, so a non-allocating hash loop delays the cancel (general GHC behaviour, not Yampa-specific).
  • Stale results need a guard. A result that was enqueued before the cancel landed would reach the next sense. Either the actuator drains the slot after cancelling or results carry a generation number. Yampa gives no help with this. It is the same race RxJS's switchMap solves by unsubscribing the inner observable.
  • CPU-bound work goes to threads outside the network. Rhine's answer is to make "outside" typed: an event clock fed from a Chan "constitute[s] the recommended way of communication between threads in Rhine" (Clock/Realtime/Event.hs).

Errors and completion ​

There is no error channel. Partial operations call usrErr (an error call, i.e. an exception at evaluation) for misuse such as repeatedly with a non-positive period or delay with a negative one (EventS.hs, Delays.hs). Failures of external work arrive as ordinary input values (Event (Either Err Hash)), which matches the sparkles convention of errors as Expected values.

Completion is not a stream concept either: an SF runs forever, and actuate returning True ends reactimate. Logical completion is modelled by Task (Task.hs), a continuation monad over SF a (b, Event c): a task produces b until it terminates with c. timeOut and abortWhen race a task against after t () or a guard event. abortWhen's doc gives the motive: "Useful for separating sequencing and termination concerns." dunai later generalised this into MSFExcept, a monad in the exception type where >>= is switching (see Related designs).

State and sharing ​

  • Value cells are hold :: a -> SF (Event a) a (zero-order hold) and accumHold :: a -> SF (Event (a -> a)) a. Both are built on epPrim, the only SF' constructor specialised for event input (SFEP). hold is a Cell!T with the version counter implied. Readers sample it every step, so it conflates by construction.
  • Conflation is the default everywhere. An Event is at most one occurrence per sample. Bursts collapse unless a …Cat operator collects them.
  • Sharing/multicast is fan-out (&&&) within the network. One SF instance's output is plumbed to many consumers by naming it once in proc. Two textual uses of the same SF value are two independent instances with separate state. A Cell that many readers share must be computed once and routed, which in a large UI makes the arrow plumbing heavy (the problem Reflex and Sodium avoid with first-class Dynamic/Cell).

Lifetime and ownership ​

Lifetime is structural: an SF lives exactly as long as the switch that contains it keeps stepping it. There are no subscriptions, disposables, owners, finalisers or teardown hooks, and for a pure machine none are needed. Dropping it is the teardown. The Space.hs leak test runs rSwitch/pSwitch/rpSwitch for two million steps precisely because a switch that kept its predecessor reachable would leak.

The catch for an effectful system: a structural drop cannot release an external resource. In the pipeline, switching the whole network off with rSwitch discards the debounce state correctly but cannot stop the worker thread. The SF must also emit CancelHash at the switching instant, and the driver must act on it. A D Scope with cancel-and-join fills exactly this gap, so that leaving a switch branch is itself the teardown of the work it started.

Testing ​

Determinism is free because time is an argument. embed :: SF a b -> (a, [(DTime, Maybe a)]) -> [b] runs an SF on an explicit list of (dt, input) samples, and deltaEncode dt xs builds such a list from plain samples (Simulation.hs). The haddock of hold is itself a test:

haskell
>>> embed (hold 1) (deltaEncode 0.1 [NoEvent, NoEvent, Event 2, NoEvent, Event 3, NoEvent])
[1,1,2,2,3,3]

The unit tests are of this form (Test/FRP/Yampa/Switches.hs: rswitch_t0 = take 20 $ embed (rSwitch (arr (+3))) rswitch_inp1, compared to a literal list). A debounce test is a list with dt = 0.1, keystrokes as Just q at chosen indices, and an assertion on which output index carries the Event. No TestClock, virtual scheduler or advanceTimeBy is needed. yampa-test adds QuickCheck generators for random dt streams (uniDistStream, generateStreamWith) and temporal-logic predicates over SFs (LTLFuture.hs: Always, Eventually, Until, Next over SF a Bool), so properties like "every query is eventually followed by a hash request within N + dt" can be checked against many sampling schedules. evalAtZero/evalAt step an SF by hand. Their doc warns that they "break the FRP abstraction by making samples discrete and step based".

The worked pipeline ​

Untested sketch (Yampa 0.15.1 API, async for the worker). Debounce reads N from the input every sample; the toggle is a structural rSwitch; the hash lives in the driver.

haskell
{-# LANGUAGE Arrows #-}
import FRP.Yampa
import Control.Concurrent.Async (async, cancel)
import Control.Concurrent.MVar
import Data.IORef

data Input  = Input  { query :: String, intervalS :: DTime, enabled :: Bool
                     , hashDone :: Event Hash }
data Cmd    = StartHash String | CancelHash
data Output = Output { cmd :: Event Cmd, shown :: Maybe Hash }

-- Fires once when local time reaches the *current* interval.
waitThenFire :: String -> SF DTime (Event String)
waitThenFire q = proc n -> do
  t <- localTime   -< ()                    -- restarts at 0 on every switch-in
  e <- iEdge False -< t >= n                -- n is re-read every sample
  once             -< e `tag` q

-- Latest-wins restart: each new query replaces the pending waiter.
debounce :: SF (Event String, DTime) (Event String)
debounce = proc (qE, n) -> rSwitch never -< (n, waitThenFire <$> qE)

pipeline :: SF Input Output
pipeline = proc inp -> do
  qE   <- edgeBy changed "" -< query inp
  fire <- debounce          -< (qE, intervalS inp)
  res  <- hold Nothing      -< Just <$> hashDone inp
  returnA -< Output (StartHash <$> fire) res
  where changed old new = if old /= new then Just new else Nothing

idle :: SF Input Output
idle = constant (Output NoEvent Nothing)

app :: SF Input Output                       -- toggle = structural lifetime
app = proc inp -> do
  on  <- iEdge False -< enabled inp
  off <- edge        -< not (enabled inp)
  out <- rSwitch idle -< (inp, (on `tag` pipeline) `lMerge` (off `tag` idle))
  returnA -< out { cmd = cmd out `lMerge` (off `tag` CancelHash) }

main :: IO ()
main = do
  worker  <- newIORef Nothing
  results <- newEmptyMVar
  let stop = readIORef worker >>= mapM_ cancel >> tryTakeMVar results >> pure ()
      actuate _ out = do
        case cmd out of
          Event (StartHash q) -> do stop
                                    a <- async (hashFileSet q >>= putMVar results)
                                    writeIORef worker (Just a)
          Event CancelHash    -> stop
          NoEvent             -> pure ()
        render (shown out) >> pure False
      sense _ = do (dt, ui) <- pollUiFrame          -- dt from the frame clock
                   done     <- tryTakeMVar results
                   pure (dt, Just ui { hashDone = maybeToEvent done })
  reactimate initialUi sense actuate app

Per-event trace (frames of dt = 16 ms, N = 300 ms):

EventInside the SFIn the driver
Keystroke during debounceedgeBy emits qE. rSwitch drops the old waitThenFire (its localTime state is garbage) and starts a new one at t = 0. Nothing fires.Nothing. No timer existed to cancel.
Debounce elapsesIn the first frame with t >= 0.3, iEdge rises, once emits, cmd = StartHash q.stop (no-op), then async hash. The UI keeps ticking.
Keystroke during hashNew qE restarts the waiter. No command yet: the running hash continues until the new debounce fires.At the next StartHash, stop calls cancel (blocks until the old thread exits), drains results, then spawns.
Interval changeintervalS is an input field. The live waiter compares against the new n on the next frame, so shrinking below the elapsed t fires immediately.Nothing.
Toggle offoff fires. rSwitch replaces pipeline with idle, discarding the pending waiter and hold. cmd = CancelHash at the same instant.stop: cancel-and-wait the worker, drain any queued result.
Result arrivessense turns the MVar into Event h. hold shows it.–

Fit with a per-frame UI. The core fits a frame loop exactly: react is "one frame", inputs are sampled UI state, outputs are a view model plus commands, and the network is deterministic and testable with embed. Three things do not fit:

  • The driver must tick every frame while anything is pending, because the SF cannot report its next deadline.
  • Work and its cancellation live in an untyped, imperative actuator, so the latest-wins guarantee for the hash is a convention, not a property of the composition.
  • A UI's many independent fields become one large tuple routed through proc, which the arrow style makes verbose.
  • Fran (Elliott & Hudak, ICFP 1997) introduced FRP with first-class Behavior a (functions of continuous time) and Event a (time-stamped occurrences), combined with until, snapshot and time transformation. Its expressiveness came from first-class signals, and the cost was the space and time leaks that AFRP was designed to remove. Elliott's later push-pull work (2009, cited in Yampa's README) kept first-class signals and attacked efficiency differently. That branch leads to Reflex and Sodium, not to Yampa.
  • Arrows, Robots, and FRP (Hudak, Courtney, Nilsson, Peterson, AFP 2002, LNCS 2638) is the tutorial presentation of Yampa on mobile robots. It is the standard introduction to proc notation, switch and reactimate.
  • Dunai / BearRiver (FRP, Refactored, Perez, Bärenz, Nilsson, Haskell Symposium 2016) generalise the step to a monad: data MSF m a b = MSF { unMSF :: a -> m (b, MSF m a b) } (InternalCore.hs). Yampa's SF is the special case m = Reader DTime. BearRiver is the Yampa API on top: type SF m = MSF (ClockInfo m) with type ClockInfo m = ReaderT DTime m (BearRiver/InternalCore.hs). The Core.hs header states the payoff: "flattening with 'EitherT' gives rise to switching, and flattening with 'ListT' gives rise to parallelism with broadcasting." Switching becomes exceptions: switch sf f = catchS ef f, and MSFExcept is "a monad in the exception type" where "'>>=' is exception handling" (MSF/Except.hs). Sequenced phases (do { try phase1; try phase2 }) replace switch combinators. That is the same control-flow-as-lifetime idea as Esterel/Céu and a close match for an Effect-returning sink. The price is that effects re-enter the step, so a dunai network can do I/O but still cannot wait asynchronously within a step.
  • Rhine (Rhine: FRP with Type-Level Clocks, Bärenz & Perez, Haskell Symposium 2018) answers "where and when does this run" in the types. class Clock m cl has associated Time cl and Tag cl and an initClock that yields an effectful tick stream (Clock.hs). The building blocks are a ClSF m cl a b (a signal function readable only under clock cl, ClSF/Core.hs), clocks, and ResamplingBuffer m cla clb a b with put at cla ticks and get at clb ticks (ResamplingBuffer.hs, e.g. keepLast, a zero-order hold, KeepLast.hs). The README's example ms500 @@ waitClock |@| ms1200 @@ waitClock >-- collect --> printEverySecond @@ waitClock composes two 500/1200 ms rhines in parallel and resamples them into a 1 s consumer, and "Uncomment the following for a type error (the clocks don't match): typeError = ms500 >>> printEverySecond" (README.md). Mapped onto sparkles, the UI frame and the CPU pool would be two clocks, the hash result an event clock fed from a channel, and the boundary a typed buffer. Mixing them without a buffer would be a compile error. The combinator mnemonic is documented (@ annotates with a clock, * composes in parallel, > sequentially, Combinators.hs). The history is the instructive part. version1.md removed the Schedule type because schedules "were not composable across monad transformers" and "several schedules were clock-specific, and basically re-implemented the constituent clocks". 1.3 dropped dunai's continuation-encoded MSF for "state automata" because it "allows GHC to optimize the code substantially" (versions.md). 1.8 replaced the SN GADT "in favour of semantic functions, for a > 100x speedup in some benchmarks" (ChangeLog.md). The new automaton package encodes a stream as StreamT { state :: s, step :: s -> m (Result s a) } with an existential s, which is a struct plus a step function. That is exactly the D design.
  • netwire (Ertugrul Söylemez; Hackage) is an arrowized "wire" library in the same family, with inhibition (a wire may produce no value) in place of Event. It is mentioned for completeness. No source was surveyed and nothing here depends on it.

Strengths ​

  • One uniform type, SF a b, for sources, transforms, continuous and discrete signals. Composition is total and glitch-free.
  • Leak-freedom by construction: no first-class signals means no retained history. This has been tested since 2003.
  • A switching family that models structural lifetime precisely, including frozen continuations that let running state be inspected, stored and re-inserted.
  • Deterministic testing with no test clock: time is a list of dts, and QuickCheck plus LTL work on top.
  • Backend-agnostic, inversion-of-control friendly (reactInit/react). It has shipped in commercial mobile games.

Weaknesses ​

  • No asynchrony, I/O, cancellation or error channel inside the model. The worked pipeline's hardest half lives in an untyped actuator.
  • No deadline query: a host cannot sleep until the next timed event.
  • Continuation encoding allocates per step, and Haskell laziness needs seq discipline. Rhine abandoned that encoding for explicit-state automata to get large speedups.
  • Arrow plumbing is verbose for wide, shallow UIs. Every shared value must be named once and routed.
  • Instantaneous-loop well-foundedness and Event sparsity are documented assumptions, not checked ones.
  • Combinatorial naming (22 switches, symbolic initialisers) is legible only after learning the grammar.

Key design decisions and trade-offs ​

DecisionRationaleTrade-off
Signal functions first-class, signals notEliminates Fran's time and space leaks; causal by constructionEvery shared signal must be routed; dynamic collections need pSwitch instead of values
Mealy machine in continuation encodingEnables first-class frozen continuations (kSwitch, pSwitch)Closure allocation per stateful step. Rhine moved to explicit state + step for speed
dt passed per step by the driverDeterminism; embed tests with no virtual clockFiring quantised to frames; no way to report the next deadline
Event = option per sampleOne SF type covers continuous and discrete; conflation is automaticBursts within a frame collapse unless the driver batches them
Switching as the only structural changeLifetime is lexical/structural; dropping a machine is teardownCannot release external resources. Effects need an explicit cancel command
d variants for decoupled switchingMakes feedback through a switch well-definedDoubles the API; the choice is subtle and only fails at run time
Hidden core, sealed primitivesUsers cannot break causality or leak-freedomUser operators must be composites; dt access needs the unsupported expose-core flag
No I/O inside SFs (Yampa); monad inside (dunai)Purity and replayability (Yampa) vs. extensibility (dunai)Yampa pushes work to the driver; dunai lets effects in but still has no asynchronous waits
Clocks in types (Rhine)"Where/when" is checked at compile time; typed resampling at clock boundariesHeavy type-level machinery; the Schedule abstraction had to be removed and redesigned

Sources ​