41
Functional Reactive Programming, Resource Types, and Wormholes Paul Hudak Yale University Department of Computer Science haskell.cs.yale.edu (Joint work with Dan Winograd-Cort) New York Haskell Users Group October 30, 2013

Functional Reactive Programming, Resource Types, and Wormholes

  • Upload
    kenyon

  • View
    53

  • Download
    0

Embed Size (px)

DESCRIPTION

Functional Reactive Programming, Resource Types, and Wormholes. Paul Hudak Yale University Department of Computer Science haskell.cs.yale.edu (Joint work with Dan Winograd-Cort) New York Haskell Users Group October 30, 2013. Background. - PowerPoint PPT Presentation

Citation preview

Slide 1

Functional Reactive Programming, Resource Types, and WormholesPaul HudakYale UniversityDepartment of Computer Sciencehaskell.cs.yale.edu

(Joint work with Dan Winograd-Cort)

New York Haskell Users GroupOctober 30, 2013

BackgroundTime-varying quantities in a PL is due to Conal Elliott (early work in C++ for animation)Fran: Functional Reactive Animation, by Elliott and Hudak: FRP implemented in Haskell, showing elegance of higher-order functions, type classes, and so on.Yampa: at Yale; an arrow-based FRP in Haskell; avoided insidious time- and space leaks; improved modularity.Since then, tons of new papers, both theoretical and applied: FranTk, Frob, FVision, Reactive Banana, FPorter, Antony Courtney: Fruit a GUI based on YampaToday will talk about a MUI (musical user interface) implemented in Euterpea (Haskell library for computer music).

Euterpea: Computer Music in HaskellWhy do this? After all, there are already many languages for computer musicMotivation:A required two-course computer-music sequence in the Computing and the Arts major at YaleThe use of modern, state-of-the-art PL ideas in a fun areaTo combine my research with my hobbyTo use music to teach (functional) programmingTo give composers powerful tools to enhance creativity

Last term, out of 20 students, 3 were Computing and the Arts majors, onewas a graduate student, and the rest were undergrads {mostly CS majors)with an interest in computer music, or a desire to learn Haskell.Euterpea Euterpea is derived from Euterpe, who was one of the nine Greek muses, or goddesses of the arts, specifically the muse of music.

Signals and Signal FunctionsSignals are time-varying quantities.Conceptually they can be thought of as functions of time:Signal a = Time aFor example:a slider is a time-varying numbera mouse is a time-varying cartesian coordinate For efficiency and modularity, we use arrows to abstract away from signals, and instead use signal functions. Conceptually:SigFun a b = Signal a -> Signal bHaskells Arrow type class make this especially easy.Key IdeaThis signal processing diagram:

is equivalent to this Euterpean code, using arrow syntax: y doy ) :: SF a b SF b c SF a c( arr (+1)is the same as constA 441From basic trigonometry:sin(nh) = 2 cos(h) sin((n-1) h) sin((n-2) h)where = 2fWe can derive a recurrence equation [Goertzel]:y(0) = 0y(1) = sin hy(n) = c y(n-1) - y(n-2) where c = 2 (cos h)Diagrammatically:Audio Example: Sine Wavez-1z-1-* cyinit: sin hinit: 0d1d2Rendered in FRPy(0) = 0y(1) = sin hy(n) = c y(n-1) - y(n-2)where c = 2 (cos h)sine :: Double -> SF () Doublesine freq = let omh = 2*pi*freq/sr d = sin omh c = 2 * cos omh in proc _ -> do rec let y = c*d1-d2 d2