Applicative data-driven programming
m ("Talk Page" -> "Talk page")
(Category:Applicative functor -> Functor)
|(4 intermediate revisions by one user not shown)|
Latest revision as of 17:46, 9 January 2011
I would love to get comments on a short (4.5 page) paper draft. It describes a very simple approach to data-driven computation and its application to GUI programming. Please use the Talk page for comments, or if you prefer you could email me instead.
I'm also very interested in suggestions or (better yet) collaboration on other applications of data-driven computation beyond GUIs, say internet-based.
 1 Abstract
- Graphical user interfaces (GUIs) are usually programmed in an "unnatural" style, in that implementation dependencies are inverted, relative to logical dependencies. We suggest that this reversal results directly from the imperative, data-driven orientation of most GUI libraries. While outputs depend on inputs from a user and semantic point of view, the data-driven approach imposes an implementation dependence of inputs on outputs.
- This paper presents simple, functional interfaces for data-driven programming in general and GUI programming in particular, in which program dependencies directly mirror logical dependencies. The interfaces are structured as applicative functors (AFs), rather than monads or arrows. Efficiency is retained while abstracting the mechanics of data-driven computation out of client programs and into reusable library code. The implementations of data-driven computation and of GUIs are also quite simple, largely due to structuring them as compositions of AFs.
 2 Files
 3 PreviewUsing "
type Source = (,) (IO () -> IO ()) `O` IO
(The paper generalizes this definition considerably.)
And of GUIs:
type UI = (->) Win `O` IO `O` (,) Layout `O` Source
These types are isomorphic to the following:
type Source' a = (IO () -> IO (), IO a) type UI' a = Win -> IO (Layout, Source' a)
and corresponding code:
apples, bananas, fruit :: UI Int apples = title "apples" $ islider (0,10) 3 bananas = title "bananas" $ islider (0,10) 7 fruit = title "fruit" $ liftA2 (+) apples bananas total :: UI (Int -> IO ()) total = title "total" showDisplay shopping :: UI (IO ()) shopping = title "Shopping List" $ fruit <**> total
As illustrated in the paper, slight variations allow for different widget layouts.