Title: Embedded Languages for Graphical Programming
1Embedded Languages for Graphical Programming
- Koen Lindström Claessen
- Chalmers University
- Gothenburg, Sweden
2Topics Today
- Fudgets Embedded language for GUI programming
- Pan Embedded language for describing pictures
and animations - Give you a flavor
3Embedded Language
- Library
- Compositional
- (Abstract) type -- modelling
- Creation functions
- Combinators
- Not always a monad ?
4Fudgets
- First real GUI library for Haskell
- Developed in 1990s (pre-monad era)
- Magnus Carlsson
- Thomas Hallgren
- Still active
5The Fudget
Messages of type a, b functional behavior
a
b
Also a graphical representation
type F a b
6Example A Button
()
()
Hello
button String -gt F () ()
7Example An Entry
String
String
12.0
entry F String String
8Fudget Composition
a
b
c
(gtlt) F a b -gt F b c -gt F a c
9Fudget Composition
a
b
c
a
(gtlt) F a b -gt F a b -gt F a b
10Example An Abstract Fudget
a
b
mapF (a -gt b) -gt F a b
11Example Spinner
12Example
13Example
spin F a (Int -gt Int) spin nil gtlt (
button gtlt mapF (\_ -gt succ) gtlt button
- gtlt mapF (\_ -gt pred) ) spinner
F Int Int spinner loop ( (mapF const gtlt
spin) gtlt count gtlt entryInt
)
nil ignores input
loop ties the knot
count does the counting
14Fudgets -- Summary
- Pick the thing to model
- A Fudget
- Widget Functionality
- Pick a type
- Design combinators
15Implementing Fudgets
- Shallow embedding?
- Deep embedding?
16Pan Functional Images
17Embedded Language for Images
type Point (Double,Double) type Image a Point
-gt a
type Region Image Bool
type Color ... type Picture Image Color
18Examples
vstrip Region vstrip (x,y) abs x lt 0.5
checker Region checker (x,y) even (floor
x floor y)
altRings Region altRings p even (distO
p) distO (x,y) sqrt (xx yy)
19Liftings
lift1 (a -gt b) -gt Image a -gt Image b lift2
(a -gt b -gt c) -gt Image a -gt Image b -gt Image c ...
over Picture -gt Picture -gt Picture over
lift2 overColor
cond Region -gt Picture -gt Picture -gt
Picture cond lift3 (\b x y -gt if b then x else
y)
20Swirling
type Filter a Image a -gt Image a
swirl Double -gt Filter a swirl r im im
. (\p -gt rotate (distO p 2 pi / -r) p
21Image Viewer
- There is an image viewer
- You can set parameters
- Sliders
- Time
22Implementation?
- How to implement this efficiently?
- Shallow implementation?
- Deep implementation?
23What we saw
- Embedded Languages
- Graphics
- Compositional
- Shallow embedding for understanding
- Deep embedding can be compiled
- Not everything is a monad
24Further Reading -- Take a look at
- Fran Functional Reactive Animations
- Yampa Fran (version 2)