FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University
Project Pitches Let’s Go!
Expression Parsing Parsec Library: data Assoc = AssocNone | AssocLeft | AssocRight data Operator tok st a = Infix (GenParser tok st (a -> a -> a)) Assoc | Prefix (GenParser tok st (a -> a)) | Postfix (GenParser tok st (a -> a)) type OperatorTable tok st a = [[Operator tok st a]]
Homework 6 Questions? No homework this week – I’ll give you extra time on the current one. I expect you to start with background research, coding, or other project-related activities.
FRP, Behaviors, and Events Event a Denotes an event stream. Each occurrence delivers value of type a keyboard :: Event Char Behavior a Denotes a continuously available value of type a mouse :: Behavior Point2
Classic FRP Operations lift0 :: a -> Behavior a lift1 :: (a -> b) -> Behavior a -> Behavior b hold :: a -> Event a -> Behavior a when :: Behavior Bool -> Event () snap :: Event a -> Behavior b -> Event b (-=>) :: Event b -> a -> Event a tags :: Event b -> [a] -> Event a (.|.) :: Event a -> Event a -> Event a switch :: Behavior a -> Event (Behavior a) -> Behavior a integral :: Behavior Double -> Behavior Double clock :: Double -> Event Double once :: Event a -> Event a
Laws of FRP Single value: signals have only one value at each time step Evaluation order independence: the update order at each time step is non-observable Purity: Identical signals initialized at the same time have the same value Convergence: continuous signals should converge to an “ideal value” as time steps decrease Immediacy: computations should not be delayed to a later time step
Dark Corners Event clashes in.|. The.|. operator can’t handle simultaneous events Running behaviors Impossible to observe a previously initialized behavior Dynamic interfaces Fixed set of GUI objects to interact with Dynamic collections We needed new primitives to implement “space invaders” Time leaks Stateful signals not yet demanded
Examples in Python Taken from the Western Computer Camp
Examples content/uploads/2011/02/icra99.pdf content/uploads/2011/02/icra99.pdf