paper
active
paper:2022-02-10-mikael-brockman-genuinely-functional-guis-pdf-43bb4b

Genuinely Functional User Interfaces

ByAntony Courtney·Conal Elliott

TL;DR

Fruit, a Functional Reactive User Interface Toolkit for Haskell, demonstrates that a formal denotational model is sufficient to define GUIs compositionally as signal transformers of type `GUI a b = ST (GUIInput, a) (Picture, b)`, where signals are functions from real-valued Time to values and signal transformers (ST) are functions from Signal to Signal. Built atop AFRP — an adaptation of Fran and FRP to Hughes's arrows framework — Fruit outlaws first-class signal values entirely, preventing the space-time leaks that plagued earlier Fran and FRP implementations; structural induction on the ST newtype suffices to prove leak-freedom. The library introduces `transformGUI`, a higher-order operator that applies any affine transform to a GUI by transforming picture output point-wise and applying the inverse transform to mouse input, enabling continuous spatial scaling (demonstrated with a `uscale 0.5` paddleball) without rewriting applications — a capability that required ground-up toolkit replacements in Pad (built on Tk) and Jazz (built on Swing). Multiple active views, unavailable in any other toolkit surveyed including Fudgets, Haggis, FranTk, and TkGofer, emerge for free from the same clipping-and-demultiplexing mechanism used by layout combinators, with a `mergeGUIInput` combinator reunifying disjoint focus signals. The prototype runs on Java2D via a purpose-built vector graphics library Haven and JNI bridge Elijah. The paper argues that grounding a GUI library in a precise denotational model makes program equivalence formally decidable, enables objective comparison of abstraction levels across libraries, and systematically yields solutions — zooming, multiple views, dynamic composition — that imperative toolkits can only approximate through ad hoc architectural extensions.

What to take away

  1. 1. Fruit defines every GUI component with the single type `GUI a b = ST (GUIInput, a) (Picture, b)`, eliminating the distinct application/container/component type hierarchy found in every prior Haskell GUI toolkit surveyed (Haggis, TkGofer, FranTk, Fudgets).
  2. 2. Signals are modeled as functions `Signal α = Time → α` over non-negative real-valued Time, and signal transformers as `ST α β = Signal α → Signal β`, with ST exposed as an abstract newtype to guarantee the implementation is provably free of space-time leaks by structural induction.
  3. 3. First-class signal values are deliberately banned — unlike Fran's `Behavior` type — because experience implementing Fran and FRP showed that first-class signals inevitably produce space-time leaks requiring the complete time-history of a signal to compute a single sample.
  4. 4. The `transformGUI` operator achieves continuous spatial scaling by applying an affine transform point-wise to the Picture output signal and its inverse point-wise to the GUIInput mouse signal, directly paralleling Pan's spatial hyperfilters for `Image → Image` functions.
  5. 5. A `uscale 0.5` transform applied via `transformGUI` produces `minipb`, a fully interactive half-size Paddleball GUI, demonstrating that continuous zoom requires zero library restructuring in Fruit whereas Pad (Tk-based) and Jazz (Swing-based) each required complete toolkit rewrites.
  6. 6. Multiple active views are obtained by composing two `view` GUIs with `besideGUI`, applying the layout combinator's existing clipping/demultiplexing, and merging the resulting disjoint GUIInput signals with a left-biased `mergeGUIInput` combinator, with no forethought required from the original GUI programmer.
  7. 7. The Fruit prototype renders via Haven, a purely functional vector graphics library using Java2D as its reference rendering engine, connected through Elijah, a purpose-built JNI bridge implemented via GreenCard.
  8. 8. To replicate the dynamic-interface pattern, a researcher can use the `accumST :: (ST b c -> d -> ST b c) -> ST b c -> ST (b, Maybe d) c` combinator, which switches in a new signal transformer each time an event occurs, as demonstrated by `dynLabels` adding a new counting label on every button press.
  9. 9. The arrows syntactic sugar (Ross Paterson's `proc`/`do` notation, implemented as a preprocessor) is identified as a prerequisite for viability: without it, composed GUIs require point-free manipulation of nested tuple types that the authors describe as 'a hopelessly unreadable mess of lifted tupling and untupling'.
  10. 10. An open question the paper raises is whether the representation of event sources as `Signal (Maybe α)` — i.e., continuous signals of Maybe values — can be made theoretically sound when dense event sources (infinitely many occurrences in a finite interval) are possible, a problem the authors acknowledge but defer to future work.

Peer brief — for seminar discussion

Courtney and Elliott's Fruit paper constructs a Haskell GUI library by first asking what a formal denotational model of a graphical user interface is, then building the library so that every type and combinator maps directly to that model. The central move is defining signals as functions from non-negative real-valued Time to values and signal transformers (ST) as functions from signals to signals, then typing every GUI component as `GUI a b = ST (GUIInput, a) (Picture, b)` — a uniform type that eliminates the application/container/widget hierarchy present in all four prior Haskell toolkits surveyed: Haggis, TkGofer, FranTk, and Fudgets. The library is built on AFRP, which adapts Functional Reactive Animation (Fran) and FRP to Hughes's arrows framework, and deliberately makes ST an abstract newtype with a fixed combinator set rather than exposing first-class signal values, which Fran's Behavior type did; this restriction makes space-time leak freedom provable by structural induction on ST. The load-bearing finding is that this single compositional model yields, without special-casing, three capabilities that required major architectural surgery in competing systems: (1) the `transformGUI` operator, which applies any affine transform by mapping the inverse transform to GUIInput and the forward transform to Picture output, enabling `uscale 0.5` to produce a fully interactive half-size Paddleball with two lines of code; (2) multiple active views via `mergeGUIInput`, which reunifies the disjoint focus signals produced by the layout combinator's existing clipping mechanism; and (3) dynamic interface composition via `accumST`, demonstrated by `dynLabels` adding labeled widgets on button press. Pad and Jazz — the state-of-the-art zoomable UI research toolkits built on Tk and Swing respectively — required complete rewrites of existing applications to gain zoom; Fruit requires none. The paper predicts that grounding library design in a denotational model will make program equivalence formally decidable and enable objective comparison of abstraction levels across libraries. A critical reader should push back on the absence of any performance evaluation: the prototype runs on a synchronous stream-processor approximation of continuous time sampled discretely, and the paper explicitly notes that a more efficient data-driven implementation is planned but not yet done — meaning all claims about practicality rest on qualitative examples rather than benchmarks against Fudgets or FranTk on non-trivial widget sets. An alternative design the authors could have explored is direct continuation-passing or monad-transformer composition (as in FranTk's MVar-based wiring) rather than the arrows abstraction, which would have traded the `proc` syntactic dependency for more conventional Haskell idiom. The focus model is also acknowledged as simplified: focus routing is based solely on mouse position, ignoring keyboard focus traversal cycles mandated by modern UI guidelines, which is a scope limitation that matters for any real deployment.

Methods (2)

Findings (2)

Questions (1)

Related work— refs + corpus + external arXiv

Cited / in-corpus / arXiv badges show which signals surfaced each row. Multi-source rows weighted higher.

+27 more

Similar preprints — Semantic Scholar

Cross-corpus bridges (1)

same_concept_as · Nomic cosine

External markdown files that talk about the same concept as this entity.

  • alexander
    Genuinely Functional User Interfacespapers/extracted/2022-02-10_Mikael-Brockman_genuinely-functional-guis.pdf_43bb4b.md0.886