functional programing at work - haskell and domain specific

600.429
FUNCTIONAL PROGRAMING AT WORK HASKELL AND DOMAIN SPECIFIC LANGUAGES
Dr. John Peterson
Western State Colorado University
SPJ!
What did you think of SPJ’s talk?
Why was this talk good?
What did you like about his presentation style?
Homework
• Project 7 is due tomorrow
• Project 8 will be up tonight – we’ll talk about it
later today.
• Questions on #7?
• Project 9 will be the last one.
Project Deadlines
Schedule:
• Before Wednesday: each project needs a
“home page” in the wiki, a name, and an
overview. Place code in a public repository
and link to your home page.
• Wednesday – work day and meetings. Come
ready to hack on your code
• Monday, Nov 12: Presentation #1: each team
gives a 7 minute presentation.
Homework #8
• Finish up FRP Engine
• Demo engine using a simple game. I’ll place a
link to the Paddleball game used in Paul’s
book in the wiki.
• Modify the engine to gather statistics for the
number of computation steps at each time
and shout at signal initialization
• Add a “let” construct to create shared signals
New Representations
What would you have to do to allow shouting? Implement let?
Gather statistics?
data Behavior a =
Behavior (Stimulus -> (Behavior a, a))
data Event a =
Event (Stimulus -> (Event a, Maybe a))
Dark Corners of FRP: Sharing
How will this work?
x = integral 1
Animate $ (el (p2 0 0) (p2 x x))
Sharing
How can we avoid recomputation?
• Create an object to explicitly represent sharing
(a “let”)
• Implicitly look for sharing at key points in the
program
Memoization
Big idea:
Turn (a -> b) into a memoized (a -> b)
We can either:
• Remember all values and replay answers
• Remember the most recent value and replay
that answer (why is this the right thing?)
The Let construct
Haskell uses “let” to make sure evaluation
happens at most once.
We can add this to a DSL:
x = myLet computation
Use this to create a sharable value.
Problem: how to give this an observable name