the essence and origins of frp -...

49
The essence and origins of FRP or How you could have invented Functional Reactive Programming Conal Elliott LambdaJam 2015 Conal Elliott The essence and origins of FRP LambdaJam 2015 1 / 27

Upload: others

Post on 05-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

The essence and origins of FRP

or

How you could have invented

Functional Reactive Programming

Conal Elliott

LambdaJam 2015

Conal Elliott The essence and origins of FRP LambdaJam 2015 1 / 27

Page 2: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

What is FRP?

Conal Elliott The essence and origins of FRP LambdaJam 2015 2 / 27

Page 3: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

FRP’s two fundamental properties

Precise, simple denotation. (Elegant & rigorous.)

Continuous time. (Natural & composable.)

Deterministic, continuous “concurrency”.

Warning: most modern “FRP” systems have neither property.

Conal Elliott The essence and origins of FRP LambdaJam 2015 3 / 27

Page 4: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

FRP’s two fundamental properties

Precise, simple denotation. (Elegant & rigorous.)

Continuous time. (Natural & composable.)

Deterministic, continuous “concurrency”.

Warning: most modern “FRP” systems have neither property.

Conal Elliott The essence and origins of FRP LambdaJam 2015 3 / 27

Page 5: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

FRP’s two fundamental properties

Precise, simple denotation. (Elegant & rigorous.)

Continuous time. (Natural & composable.)

Deterministic, continuous “concurrency”.

Warning: most modern “FRP” systems have neither property.

Conal Elliott The essence and origins of FRP LambdaJam 2015 3 / 27

Page 6: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

FRP’s two fundamental properties

Precise, simple denotation. (Elegant & rigorous.)

Continuous time. (Natural & composable.)

FRP is not about:

graphs,

updates and propagation,

streams,

doing

Conal Elliott The essence and origins of FRP LambdaJam 2015 4 / 27

Page 7: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

FRP’s two fundamental properties

Precise, simple denotation. (Elegant & rigorous.)

Continuous time. (Natural & composable.)

FRP is not about:

graphs,

updates and propagation,

streams,

doing

Conal Elliott The essence and origins of FRP LambdaJam 2015 4 / 27

Page 8: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why (precise & simple) denotation?

Separates specification from implementation.

Simple so that we can reach conclusions.

Precise so that our conclusions will be true.

Denotations have elegant, functional-friendly style.

An API is a language for communicating about a domain.

It helps to (really) understand what we’re talking about.

Conal Elliott The essence and origins of FRP LambdaJam 2015 5 / 27

Page 9: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why (precise & simple) denotation?

Separates specification from implementation.

Simple so that we can reach conclusions.

Precise so that our conclusions will be true.

Denotations have elegant, functional-friendly style.

An API is a language for communicating about a domain.

It helps to (really) understand what we’re talking about.

Conal Elliott The essence and origins of FRP LambdaJam 2015 5 / 27

Page 10: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why (precise & simple) denotation?

Separates specification from implementation.

Simple so that we can reach conclusions.

Precise so that our conclusions will be true.

Denotations have elegant, functional-friendly style.

An API is a language for communicating about a domain.

It helps to (really) understand what we’re talking about.

Conal Elliott The essence and origins of FRP LambdaJam 2015 5 / 27

Page 11: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why continuous & infinite (vs discrete/finite) time?

Same benefits as for space (vector graphics):

Transformation flexibility with simple & precise semantics.

Modularity/reusability/composability:

Fewer assumptions, more uses (resolution-independence).

More info available for extraction.

Integration and differentiation: natural, accurate, efficient.

Quality/accuracy.

Efficiency (adapative).

Reconcile differing input sampling rates.

Principle: Approximations/prunings compose badly, so postpone.

See Why Functional Programming Matters.

Conal Elliott The essence and origins of FRP LambdaJam 2015 6 / 27

Page 12: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why continuous & infinite (vs discrete/finite) time?

Same benefits as for space (vector graphics):

Transformation flexibility with simple & precise semantics.

Modularity/reusability/composability:

Fewer assumptions, more uses (resolution-independence).

More info available for extraction.

Integration and differentiation: natural, accurate, efficient.

Quality/accuracy.

Efficiency (adapative).

Reconcile differing input sampling rates.

Principle: Approximations/prunings compose badly, so postpone.

See Why Functional Programming Matters.

Conal Elliott The essence and origins of FRP LambdaJam 2015 6 / 27

Page 13: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why continuous & infinite (vs discrete/finite) time?

Same benefits as for space (vector graphics):

Transformation flexibility with simple & precise semantics.

Modularity/reusability/composability:

Fewer assumptions, more uses (resolution-independence).

More info available for extraction.

Integration and differentiation: natural, accurate, efficient.

Quality/accuracy.

Efficiency (adapative).

Reconcile differing input sampling rates.

Principle: Approximations/prunings compose badly, so postpone.

See Why Functional Programming Matters.

Conal Elliott The essence and origins of FRP LambdaJam 2015 6 / 27

Page 14: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why continuous & infinite (vs discrete/finite) time?

Same benefits as for space (vector graphics):

Transformation flexibility with simple & precise semantics.

Modularity/reusability/composability:

Fewer assumptions, more uses (resolution-independence).

More info available for extraction.

Integration and differentiation: natural, accurate, efficient.

Quality/accuracy.

Efficiency (adapative).

Reconcile differing input sampling rates.

Principle: Approximations/prunings compose badly, so postpone.

See Why Functional Programming Matters.

Conal Elliott The essence and origins of FRP LambdaJam 2015 6 / 27

Page 15: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Why continuous & infinite (vs discrete/finite) time?

Same benefits as for space (vector graphics):

Transformation flexibility with simple & precise semantics.

Modularity/reusability/composability:

Fewer assumptions, more uses (resolution-independence).

More info available for extraction.

Integration and differentiation: natural, accurate, efficient.

Quality/accuracy.

Efficiency (adapative).

Reconcile differing input sampling rates.

Principle: Approximations/prunings compose badly, so postpone.

See Why Functional Programming Matters.

Conal Elliott The essence and origins of FRP LambdaJam 2015 6 / 27

Page 16: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Semantics

Central abstract type: Behavior a — a “flow” of values.

Precise & simple semantics:

µ :: Behavior a Ñ pT Ñ aq

where T “ R (reals).

Much of API and its specification can follow from this one choice.

Conal Elliott The essence and origins of FRP LambdaJam 2015 7 / 27

Page 17: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Semantics

Central abstract type: Behavior a — a “flow” of values.

Precise & simple semantics:

µ :: Behavior a Ñ pT Ñ aq

where T “ R (reals).

Much of API and its specification can follow from this one choice.

Conal Elliott The essence and origins of FRP LambdaJam 2015 7 / 27

Page 18: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Semantics

Central abstract type: Behavior a — a “flow” of values.

Precise & simple semantics:

µ :: Behavior a Ñ pT Ñ aq

where T “ R (reals).

Much of API and its specification can follow from this one choice.

Conal Elliott The essence and origins of FRP LambdaJam 2015 7 / 27

Page 19: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Original formulation

Conal Elliott The essence and origins of FRP LambdaJam 2015 8 / 27

Page 20: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

API

time :: Behavior T

lift0 :: a Ñ Behavior a

lift1 :: pa Ñ bq Ñ Behavior a Ñ Behavior b

lift2 :: pa Ñ b Ñ cq Ñ Behavior a Ñ Behavior b Ñ Behavior c

timeTrans :: Behavior a Ñ Behavior T Ñ Behavior a

integral :: VS a ñ Behavior a Ñ T Ñ Behavior a

...

instance Num a ñ Num pBehavior aq where ...

...

Reactivity later.

Conal Elliott The essence and origins of FRP LambdaJam 2015 9 / 27

Page 21: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Semantics

µ time “ λt Ñ t

µ plift0 aq “ λt Ñ a

µ plift1 f xsq “ λt Ñ f pµ xs tq

µ plift2 f xs ysq “ λt Ñ f pµ xs tq pµ ys tq

µ ptimeTrans xs ttq “ λt Ñ µ xs pµ tt tq

instance Num a ñ Num pBehavior aq where

fromInteger “ lift0 ˝ fromInteger

p`q “ lift2 p`q

...

Conal Elliott The essence and origins of FRP LambdaJam 2015 10 / 27

Page 22: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Semantics

µ time “ id

µ plift0 aq “ const a

µ plift1 f xsq “ f ˝ µ xs

µ plift2 f xs ysq “ liftA2 f pµ xsq pµ ysq

µ ptimeTrans xs ttq “ µ xs ˝ µ tt

instance Num a ñ Num pBehavior aq where

fromInteger “ lift0 ˝ fromInteger

p`q “ lift2 p`q

...

Conal Elliott The essence and origins of FRP LambdaJam 2015 11 / 27

Page 23: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Events

Secondary type:

µ :: Event a Ñ rpT , aqs -- non-decreasing times

never :: Event a

once :: T Ñ a Ñ Event a

p.|.q :: Event a Ñ Event a Ñ Event a

pùñq :: Event a Ñ pa Ñ bq Ñ Event b

predicate :: Behavior Bool Ñ Event pq

snapshot :: Event a Ñ Behavior b Ñ Event pa, bq

Exercise: define semantics of these operations.

Conal Elliott The essence and origins of FRP LambdaJam 2015 12 / 27

Page 24: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Reactivity

Reactive behaviors are defined piecewise, via events.

:

switcher :: Behavior a Ñ Event pBehavior aq Ñ Behavior a

Semantics:

µ pb0 ‘switcher ‘ eq t “ µ plast pb0 : before t pµ eqqq t

before :: T Ñ rpT , aqs Ñ ra s

before t os “ ra | pta, aq Ð os, ta ă t s

Important: ta ă t , rather than ta ď t .

Conal Elliott The essence and origins of FRP LambdaJam 2015 13 / 27

Page 25: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Reactivity

Reactive behaviors are defined piecewise, via events.:

switcher :: Behavior a Ñ Event pBehavior aq Ñ Behavior a

Semantics:

µ pb0 ‘switcher ‘ eq t “ µ plast pb0 : before t pµ eqqq t

before :: T Ñ rpT , aqs Ñ ra s

before t os “ ra | pta, aq Ð os, ta ă t s

Important: ta ă t , rather than ta ď t .

Conal Elliott The essence and origins of FRP LambdaJam 2015 13 / 27

Page 26: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Reactivity

Reactive behaviors are defined piecewise, via events.:

switcher :: Behavior a Ñ Event pBehavior aq Ñ Behavior a

Semantics:

µ pb0 ‘switcher ‘ eq t “ µ plast pb0 : before t pµ eqqq t

before :: T Ñ rpT , aqs Ñ ra s

before t os “ ra | pta, aq Ð os, ta ă t s

Important: ta ă t , rather than ta ď t .

Conal Elliott The essence and origins of FRP LambdaJam 2015 13 / 27

Page 27: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

A more elegant specification

for FRP (teaser)

Conal Elliott The essence and origins of FRP LambdaJam 2015 14 / 27

Page 28: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

API

Replace operations with standard abstractions where possible:

instance Functor Behavior where ...

instance Applicative Behavior where ...

instance Monoid a ñ Monoid pBehavior aq where ...

instance Functor Event where ...

instance Monoid pEvent aq where ...

Why?

Less learning, more leverage.

Specifications and laws for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 15 / 27

Page 29: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

API

Replace operations with standard abstractions where possible:

instance Functor Behavior where ...

instance Applicative Behavior where ...

instance Monoid a ñ Monoid pBehavior aq where ...

instance Functor Event where ...

instance Monoid pEvent aq where ...

Why?

Less learning, more leverage.

Specifications and laws for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 15 / 27

Page 30: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Specifications for free

The instance’s meaning follows the meaning’s instance:

µ pfmap f asq ” fmap f pµ asq

µ ppure aq ” pure a

µ pfs ă̊ą xsq ” µ fs ă̊ą µ xs

µ ε ” ε

µ ptop ˛ botq ” µ top ˛ µ bot

Corresponds exactly to the original FRP denotation.

Follows inevitably from a domain-independent principle.

Laws hold for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 16 / 27

Page 31: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Specifications for free

The instance’s meaning follows the meaning’s instance:

µ pfmap f asq ” fmap f pµ asq

µ ppure aq ” pure a

µ pfs ă̊ą xsq ” µ fs ă̊ą µ xs

µ ε ” ε

µ ptop ˛ botq ” µ top ˛ µ bot

Corresponds exactly to the original FRP denotation.

Follows inevitably from a domain-independent principle.

Laws hold for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 16 / 27

Page 32: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

History

Conal Elliott The essence and origins of FRP LambdaJam 2015 17 / 27

Page 33: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1983–1989 at CMU

I went for graphics.

Did program transformation, FP, type theory.

Class in denotational semantics.

Conal Elliott The essence and origins of FRP LambdaJam 2015 18 / 27

Page 34: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1989 at CMU

Kavi Arya’s visit:

Functional animation

Streams of pictures

Elegant

, mostly

John Reynolds’s insightful remark:

“You can think of streams as functions from the natural numbers.

Have you thought about functions from the reals instead?

Doing so might help with the awkwardness of interpolation.”

Continuous time!

I finished my dissertation anyway.

Conal Elliott The essence and origins of FRP LambdaJam 2015 19 / 27

Page 35: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1989 at CMU

Kavi Arya’s visit:

Functional animation

Streams of pictures

Elegant, mostly

John Reynolds’s insightful remark:

“You can think of streams as functions from the natural numbers.

Have you thought about functions from the reals instead?

Doing so might help with the awkwardness of interpolation.”

Continuous time!

I finished my dissertation anyway.

Conal Elliott The essence and origins of FRP LambdaJam 2015 19 / 27

Page 36: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1989 at CMU

Kavi Arya’s visit:

Functional animation

Streams of pictures

Elegant, mostly

John Reynolds’s insightful remark:

“You can think of streams as functions from the natural numbers.

Have you thought about functions from the reals instead?

Doing so might help with the awkwardness of interpolation.”

Continuous time!

I finished my dissertation anyway.

Conal Elliott The essence and origins of FRP LambdaJam 2015 19 / 27

Page 37: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1989 at CMU

Kavi Arya’s visit:

Functional animation

Streams of pictures

Elegant, mostly

John Reynolds’s insightful remark:

“You can think of streams as functions from the natural numbers.

Have you thought about functions from the reals instead?

Doing so might help with the awkwardness of interpolation.”

Continuous time!

I finished my dissertation anyway.

Conal Elliott The essence and origins of FRP LambdaJam 2015 19 / 27

Page 38: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1990–93 at Sun: TBAG

3D geometry etc as first-class immutable values.

Animation as immutable functions of continuous time.

Multi-way constraints on time-functions.

Off-the-shelf constraint solvers (DeltaBlue & SkyBlue from UW).

Differentiation, integration and ODEs specified via derivative.

Adaptive Runge-Kutta-5 solver (fast & accurate).

Reactivity via assert/retract (high-level but imperative).

Optimizing compiler via partial evaluation.

In Common Lisp, C++, Scheme.

Efficient multi-user distributed execution for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 20 / 27

Page 39: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1990–93 at Sun: TBAG

3D geometry etc as first-class immutable values.

Animation as immutable functions of continuous time.

Multi-way constraints on time-functions.

Off-the-shelf constraint solvers (DeltaBlue & SkyBlue from UW).

Differentiation, integration and ODEs specified via derivative.

Adaptive Runge-Kutta-5 solver (fast & accurate).

Reactivity via assert/retract (high-level but imperative).

Optimizing compiler via partial evaluation.

In Common Lisp, C++, Scheme.

Efficient multi-user distributed execution for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 20 / 27

Page 40: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1990–93 at Sun: TBAG

3D geometry etc as first-class immutable values.

Animation as immutable functions of continuous time.

Multi-way constraints on time-functions.

Off-the-shelf constraint solvers (DeltaBlue & SkyBlue from UW).

Differentiation, integration and ODEs specified via derivative.

Adaptive Runge-Kutta-5 solver (fast & accurate).

Reactivity via assert/retract (high-level but imperative).

Optimizing compiler via partial evaluation.

In Common Lisp, C++, Scheme.

Efficient multi-user distributed execution for free.

Conal Elliott The essence and origins of FRP LambdaJam 2015 20 / 27

Page 41: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1994–1996 at Microsoft Research: RBML/ActiveVRML

Programming model & fast implementation for new 3D hardware.

TBAG + denotative/functional reactivity.

Add event algebra to behavior algebra.

Reactivity via behavior-valued events.

Drop multi-way constraints “at first”.

Started in ML as “RBML”.

Rebranded to “ActiveVRML”, then “DirectAnimation”.

Conal Elliott The essence and origins of FRP LambdaJam 2015 21 / 27

Page 42: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1994–1996 at Microsoft Research: RBML/ActiveVRML

Programming model & fast implementation for new 3D hardware.

TBAG + denotative/functional reactivity.

Add event algebra to behavior algebra.

Reactivity via behavior-valued events.

Drop multi-way constraints “at first”.

Started in ML as “RBML”.

Rebranded to “ActiveVRML”, then “DirectAnimation”.

Conal Elliott The essence and origins of FRP LambdaJam 2015 21 / 27

Page 43: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1994–1996 at Microsoft Research: RBML/ActiveVRML

Programming model & fast implementation for new 3D hardware.

TBAG + denotative/functional reactivity.

Add event algebra to behavior algebra.

Reactivity via behavior-valued events.

Drop multi-way constraints “at first”.

Started in ML as “RBML”.

Rebranded to “ActiveVRML”, then “DirectAnimation”.

Conal Elliott The essence and origins of FRP LambdaJam 2015 21 / 27

Page 44: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1995–1999 at MSR: RBMH/Fran

Found Haskell: reborn as “RBMH” (research vehicle).

Very fast implementation via sprite engine.

John Hughes suggested using Arrow .

Conal Elliott The essence and origins of FRP LambdaJam 2015 22 / 27

Page 45: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1999 at MSR: first try at push-based implementation

Algebra of imperative event listeners.

Challenges:

Garbage collection & dependency reversal.

Determinacy of timing & simultaneity.

I doubt anyone has gotten correct.

Conal Elliott The essence and origins of FRP LambdaJam 2015 23 / 27

Page 46: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

2009: Push-pull FRP

Minimal computation, low latency, provably correct.

Push for reactivity and pull for continuous phases.

“Push” is really blocked pull.

More elegant API:

Standard abstractions.

Semantics as homomorphisms.

Laws for free.

Reactive normal form, via equational properties (denotation!).

Uses lub (basis of PL semantics).

Implementation subtleties & GHC RTS bugs. Didn’t quite work.

Conal Elliott The essence and origins of FRP LambdaJam 2015 24 / 27

Page 47: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

1996–2014: Paul Hudak / Yale

Paul Hudak visited MSR in 1996 or

so and saw RBMH.

Encouraged publishing, and suggested

collaboration.

Proposed names “Fran” & “FRP”.

Many FRP-based papers and theses.

July 15, 1952 – April 29, 2015

Conal Elliott The essence and origins of FRP LambdaJam 2015 25 / 27

Page 48: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

Questions

Conal Elliott The essence and origins of FRP LambdaJam 2015 26 / 27

Page 49: The essence and origins of FRP - Conalconal.net/talks/essence-and-origins-of-frp-lambdajam-2015.pdf · The essence and origins of FRP or How you could have invented Functional Reactive

“But computers are discrete, ...”

Conal Elliott The essence and origins of FRP LambdaJam 2015 27 / 27