Functional Graphical User Interfaces An Implementation based on GTK

Size: px
Start display at page:

Download "Functional Graphical User Interfaces An Implementation based on GTK"

Transcription

1 Functional Graphical User Interfaces An Implementation based on GTK Micha l Pa lka June 22, Introduction Graphical user interfaces (GUIs) as we know them today were created over 20 years ago, yet they are still notoriously difficult to implement. Evan a moderately complex interface requires a large amount of code to implement it. A study at Adobe [8] has shown that the amount of GUI event handling code reaches 1/3 in many projects and is a source of one-halve of bugs. This indicates that the popular techniques used in implementing GUIs are rather low-level because they require writing much more code that seems to be necessary. Despite numerous attempts at changing it, the usual imperative style of programming based on callbacks is still ubiquitous and all mainstream GUI toolkits are based on it. In that scheme, GUI functionality is implemented using callback routines which are triggered by external events, such as button click, and which manually update the program state along with performing required actions. This causes the GUI code responsible for updates to be split into small pieces scattered over multiple callbacks which operate on the same shared state. What emerges is code that that is very unstructured and is often metaphorically described by the term spaghetti code. Another problem that contributes to the difficulty of implementing GUIs is the lack of compositionality of code written in the callback style. There is no easy way of connecting two components together as events originating in one of them might require changing the state of the other which can be done by defining the components specifically a priori, or equipping them with complicated callback interfaces. To conquer these problems, we will present a programming model based on explicit modeling of dataflow diagrams. We assert that this representation is more natural and preserves locality of code much better that the callback style. Dataflow computation was found to be cleanly expressible in Haskell where combinator libraries provide means of creating domain-specific languages embedded in Haskell. Early efforts to employ dataflow representation of GUIs in Haskell include Fudgets [1] developed by Thomas Hallgren and Magnus Carlsson. Dataflow programming has been chosen as a base for Fudgets because it provided a functional feel of programming GUIs. Later, the theme was picked up by the FRP group from Yale University who developed Fran [4], a framework for Functional Reactive Programming which was built around the concept of providing manageable denotational semantics to aid reasoning about 1

2 the code. Subsequently the framework was refined to be based on Arrows, a framework for encoding dataflow diagrams, and called YAMPA [7]. In order to model reactive systems that dynamically change their structure, a reactive programming framework must provide means of specifying changes to dataflow diagrams that occur over time. To implement this, the FRP frameworks based on Haskell use a concept called switching which means replacing a fragment of the diagram with a new one when a specific event happens. Implementation of switching combinators impose significant constraints on the underlying structure of FRP libraries and complicates interaction with imperative GUI libraries. Fran and YAMPA are both general reactive programming libraries and do not contain GUI toolkits, however they serve as a base of several GUI toolkits, the most notable being Fruit [3, 2]. Fruit is an advanced functional GUI toolkit which is developed on top of YAMPA and uses a functional graphics library for drawing widgets. For experts, it supports, among other things, continuous and discrete signals, animation, switching and dynamic collections. Fruit has been adapted to run on top of an imperative GUI toolkit, wxwidgets, by Bart Robinson in wxfruit [10] project. Running on top of a mainstream GUI toolkit is beneficial because all the widgets do not have to be implemented from scratch. However, interfacing the imperative style of wxwidgets with the functional style of Fruit raised issues that made it difficult to implement switching combinators properly for widgets and reduced the possibility to use wxfruit for creating dynamic GUIs. In this report we present a functional GUI toolkit for Haskell similar to wxfruit, however developed from scratch to be based on GTK+ (called GTK later in the report), another mainstream GUI toolkit. The presented toolkit uses GTK for drawing widgets on the screen as well as for laying them out. Central idea to the toolkit is that its implementation performs actions only in response to external events and remains idle otherwise. Our main contributions are as follows: Our implementation uses GTK for drawing widgets without giving up switching combinators; we provide a simple switching combinator. It is implemented using a novel technique based on restricted discrete signal types and double-step evaluation which allows for switching GTK widgets. We provide an efficient way of supporting external data models, or Model- View-Controller separation, for complex data models. It is possible, for instance, to have two text views showing the same buffer and populating changes entered into any of them in an effective manner. Earlier functional toolkits did support MVC, however no emphasis was placed on this functionality and efficient propagation of changes was impossible. Our implementation has several limits: It does not support animated widgets, since the implementation can wake up only in response to user actions. We do not provide advanced switching combinators. Layout treatment is limited to hierarchical layout using simple layout combinators. 2

3 () simpletextentry String String simpletextoutput () Figure 1: Diagrams of components representing text entries The remainder of the report is structured as follows. Section 2 provides a high-level overview of the toolkit and underlying computation model. Section 3 presents a more technical description along with a short introduction to Haskell and the Arrows framework useful for understanding the section. Section 4 presents the selected details from the internals of the toolkit. Section 5 discusses the limitations. Our contributions are located mainly in sections 3.5 and 4. 2 Overview of the toolkit In this section we will informally introduce the computation model that is the foundation of our toolkit by presenting example GUIs built using it. The model closely resembles synchronous dataflow programming. We will be building our GUIs out of components, called signal transformers, which we will connect together to form a diagram which will also be represented by a signal transformer. Each signal transformer represents a widget or a larger fragment of a GUI and contains input and output ports for exchanging data with other parts of the program. We can interact with a signal transformer only by (1) influencing it by feeding it appropriate input and (2) getting information from it by reading its output. This ensures that the functionality of components is well encapsulated with input and output ports being the only interface to them. 2.1 Primitive elements First diagram in Figure 1 illustrates an example primitive component of a GUI, a text field whose purpose is to hold text entered by user. We indicate that simpletextentry outputs a string of characters by drawing an outgoing arrow labeled with String. Even though simpletextentry doesn t take any data on input we still add an input port to it for consistency with other components. In this case input has type () which is a type that has only one value and thus yields no information. Programmers with C background may call it void while functional programmers will probably pronounce it unit. As expected, simpletextentry outputs the text that the widget holds at the moment. We call input and output of simpletextentry continuous signals because they yield values at any given moment of execution. However, all continuous signals are in fact step signals since their values change only on event occurrences and remain constant otherwise. We will need another simple component to display text computed by an application. The component simpletextoutput shown in Figure 1 has a signature dual to that of simpletextentry that is it takes a String and outputs nothing (()). Note that simpletextoutput is suitable for output only and that the user is prevented from editing it directly. 3

4 () String simpletextentry simpletextoutput () Figure 2: Diagram of a simple GUI which accepts a string in the first text field and prints it in the second Figure 3: Actual GUI from Figure Composite GUIs We can imagine a very simple GUI that we can build using these two components. Figure 2 shows diagram of a GUI where output of a text entry is fed to another text field. Anything that is entered in the first text field ends up also in the second. The actual window realizing the diagram is shown in Figure 3. This example is a GUI that does no explicit computations on the data; we merely move data around from one widget to another. To process data we introduce a special kind of a signal transformer. For any Haskell function f of type a -> b, which takes a value of type a and returns a value of type b, our toolkit allows the programmer to build a new component, written arr f, that performs the computations of f on its input and delivers the result to its output. Of course arr f has an input port of type a and an output port of type b and it does not exhibit itself as a visible widget. Once we can express arbitrary computations we are ready to present a more complex example. Here we are going to ask the user to provide her first and last name and show a greeting message to her. The function that will create the message has type (String, String) -> String which means that it takes a pair of Strings and returns a String. It can be defined as follows: makemessage (firstname, lastname) = "Hello, " ++ firstname ++ " " ++ lastname ++ "!" where ++ is the operator for concatenation of strings. The diagram of the second example is shown in Figure 4. It consists of two text entries whose outputs are delivered to the component enclosing makemessage and a text field that displays the output of that function. Please note that even though the arr makemessage component has a single input, we draw two arrows because it accepts a pairs of values on its input. Physically, we will consolidate the two values into a pair before handing them to the component. Resulting GUI is shown in Figure 5. Note on semantics The computation model of signal transformers is completely synchronous, which means that the implementation calculates all needed 4

5 () simpletextentry String () simpletextentry String arr makemessage String simpletextoutput () Figure 4: Diagram of a simple GUI which accepts two strings and displays a string which is computed from them Figure 5: example GUI values in channels before processing next event. For instance, this means that it will wait for the data to reach simpletextoutput in Figure 2 after a change before dealing with the next change. 2.3 Discrete signals In the examples we have seen so far, the channels were carrying continuous data, in the sense that the data is being transmitted even in the absence of any related event. For instance, in the example from Figure 4, when the user types Haskell, Curry is still transmitted from the Last name widget to the Message widget. On the other hand, we call a signal In order to model reactions to discrete events like button clicks we need a specific type of signals which will be used to send notifications about the events. Discrete signals will be transmitted over the same channels as normal, continuous values, but will be represented by a datatype Sparse a which will denote a discrete signal containing a value of type a. A value of type Sparse a will yield no information when there is no event and will contain a value of type a on event occurrence. For instance, in the case of simplebutton, which represents an ordinary button, we don t want any data associated with an event to be transmitted, thus its output port has type of Sparse (). The datatype for transmitting discrete events, Sparse a, is defined as an opaque datatype, which means that we can not create or analyze its values directly. Instead, the programmer is forced to use special functions which are provided for manipulating them. We will be able to perform two operations on Sparse a: (1) operating on a value carried by an existing discrete signal and (2) merging two discrete signals that are parametrized by the same type. To 5

6 Sparse (a -> a) stepaccum init a Figure 6: stepaccum signal transformer modify a value carried by a discrete signal we will use the following function fmap :: (a -> b) -> Sparse a -> Sparse b 1 which takes an operation on values as an argument and applies it on each value that arrives in the signal. In case where the function to be applied is constant we can use a specialized version which replaces the arriving values with a predetermined value tag :: b -> Sparse a -> Sparse b If we have two discrete signals carrying the same type of value we can produce a signal which fires each time an event arrives on either of them merge :: Sparse a -> Sparse a -> Sparse a The merge operator preferes the left value in case of simultaneous occurence. Restricting manipulation of Sparse a to these functions entails that discrete signals can only be lit as a result of events originating from external sources. In other words, if a discrete signal is fired, we know that we are processing an external event. This restriction to the computation model makes it possible for the implementation to wake up only on external events and remain idle otherwise. Due to the opaque nature of this type we are unable to directly convert Sparse a values to ordinary, continuous signals. For this we will use a specially provided operation, stepaccum shown in Figure 6, which is also the basic operation for creating stateful signal transformers. A signal transformer stepaccum init starts with an initial value init of type a as its state and updates it applying the function that shows up with each event on input. It also exposes the value of its state continuously on its output effectively making it a stepping operator. A diagram of an example calculator that uses discrete signals is shown in Figure 7. Discrete signals originate from buttons labeled by digits and operations are tagged by appropriate values of EventDesc, a type which is a union of digits and operations. Next all the tagged signals are merged using multiple applications of merge displayed as a triangle in the diagram. Resulting discrete signal is routed to a component that implements the proper logic of the calculator and is decomposed below. Firstly, a transition function on state is selected by applying trans function to a value of EventDesc and the resulting discrete signal is fed to an instance of stepaccum which applies it to the state. The state is constantly consulted by a component which extracts from it a number to be displayed and presents it as a String. 1 We read this: fmap has type (a -> b) -> Sparse a -> Sparse b 6

7 Sparse EventDesc mainlogic String simpletextoutput +... = Sparse (State -> State) Sparse EventDesc arr (fmap trans) stepaccum initstate State arr statetodisp String mainlogic Figure 7: Simplified diagram of a calculator 2.4 Advanced Idioms Text entry widgets that were presented so far have simple interfaces that are suitable for input-only or output-only; we are not capable of creating a text entry that a user can edit and whose contents can be altered by the program. To solve this problem in an elegant fashion we need to introduce some sort of separation between the widget displaying the data and its model, that is the component that holds the data. This approach is commonly called a Model- View-Controller (MVC) separation and identifies three parts: (1) the model, which is a datastructure, (2) a view or multiple views that are widgets displaying the data from the model and (3) the controller, which is responsible for the logic of updates. We will realize the MVC separation using decomposition shown in Figure 8 in which textentry is the view whereas the model and the controller are hidden in textmodel component. When the user edits the entry, the event is signaled by sending appropriate value of TextDelta by the textentry which describes the change made by the user. The controller then decides what to do, typically to apply the delta to the buffer it holds, and sends the updated data 2 to its output together with the right delta value. For example, the controller might decide to capitalize all input done by the user. When abc is entered to the text entry, the discrete signal delivers a value of type TextDelta, InsertText pos "abc" (pos denotes position where the text was inserted) to the controller which decides to insert ABC instead in the same position. It applies the change to the text buffer and exposes the new buffer on its output along with signaling the change that occurred, that is the insertion of ABC. Finally, this data reaches the component that displays it. The component does not have to read the whole updated buffer that arrived on input which might be rather big; alternatively it can make use of the provided delta value and efficiently make local changes. 2 Physically, only a reference to data is sent 7

8 TextEntry Sparse TextDelta Sparse TextDelta textmodel TextEntry (String, Sparse TextDelta) Figure 8: Two widgets sharing a single model a (b, Sparse c) initial a initial b Sparse c a next x b switch initial next Figure 9: Switching combinator Using this scheme it is possible to easily express a GUI where two text entries share the same model. It is enough to perform merge operation on discrete events produced by the text entries, feed the resulting signal to the model-controller component and route its output to all views. Example of such GUI is shown in Figure 8. Note that this design involves no redundant state as only the model holds the data. 2.5 Dynamic interfaces Interfaces can change the configuration of widgets by using a simple switching combinator switch. The switch combinator is a GUI component that accepts two arguments: a component that will be the initial configuration and a function which takes a single argument and returns a component that will replace the initial one. Figure 9 shows the switch combinator together with diagrams of its arguments: a component initial and a function next taking an argument of type c. In the beginning, switch initial next behaves like its first argument with the exception that it outputs only the first component of pair. Second component is examined by switch which waits until an event occurs on it. On event, the value carried by it is passed to next function that produces a component that will replace the whole switch. 3 Technical overview In this section we will describe our toolkit in more concrete terms. It will start with a quick primer to Haskell and then we will proceed to explaining how to construct primitive and composite GUIs. 8

9 3.1 Brief introduction to Haskell Haskell is a non-strict statically-typed purely-functional programming language. Being a purely-functional language means that computations and side-effects are clearly separated. All computations take form of evaluation of expressions whereas all side-effects are modeled explicitly, for example as a list of actions to do, or are encapsulated in control structures such as monads. Haskell programs consist of definitions written in a form of equations. Let us recall a definition from earlier in the report which will serve as an example. makemessage (firstname, lastname) = "Hello, " ++ firstname ++ " " ++ lastname ++ "!" It defines a function that takes one argument, a pair of Strings, and returns a message that contains both of them. Note that even though Haskell is statically typed we didn t have to declare the type of makemessage. Instead, the type is inferred by the compiler to be (String, String) -> String which denotes a type of functions from a pair of Strings to a String. The type can be guessed by the compiler because String is the only type that can be used this way. We will be writing typing judgments in following way: makemessage :: (String, String) -> String which is pronounced makemessage has type (String, String) -> String. Evaluation of functions in Haskell is performed differently than in most other languages. Instead of calling a function after evaluating all of its arguments, the arguments are passed unevaluated and their values computed only if needed. This strategy is called non-strict evaluation and is a very advantageous feature. Among other things, it aids embedding domain-specific languages in Haskell. Fundamental way of representing data in Haskell is by creating algebraic datatypes. Example definition looks like this data Bool = False True which defines a datatype with two values given by constructors True and False. We can also create polymorphic datatypes, that is datatypes which depend on their type parameters. data Pair a b = Pair a b In this context Pair is the name of the datatype and a and b are type variables which range over all types. On the right-hand side of equality sign we have defined one constructor Pair a b which holds one value of each parameter type. Therefore, a value of type Pair Int String, for example, holds one integer and one String. Type Pair a b is isomorphic to (a, b) which is the standard Haskell type for representing pairs. As mentioned earlier, computations in Haskell are completely separated from side-effects. The separation is accomplished by encapsulating all side effects in a special type, IO a which represents a computation possibly involving sideeffects and yielding a result of type a. For example, if we wanted to create a function from a to b that yields side-effects, it would be of type a -> IO b. 9

10 a arr f b a v b v >>> w v c a v c first v b Figure 10: Diagrams of basic operations on arrows 3.2 Signal transformers We will be representing our GUI components as signal transformers each of which has type Signal a b. Informally, a value of Signal a b denotes a signal function which transforms values of type a into values of type b. For example, we can imagine a signal function incr :: Signal Int Int which takes an integer and outputs its successor. We will also use values of type Signal a b to represent widgets visible on the screen. For example, a signal transformer representing a text entry as in Figure 1 has type simpletextentry :: Signal () String which indicates that it doesn t take any data from other computations and that it outputs a string that has been entered to it. We should stress the difference between pure signal transformers and rich signal transformers. Whereas incr is a signal transformer that acts as a regular, pure function whose output is fully determined by the input, simpletextentry, on the other hand, is not pure because its output does not only depend on its input, which is constant, and also because it exhibits itself as a visible widget. The type Signal a b provides a very simple interface to widgets. The only thing that we can do with a widget is to connect its input to a source of data and collect its output. Therefore, we view a widget as a black box with input and output channels. 3.3 Composing signal transformers Once we have primitive building blocks for an interface we can start putting them together. For this we will be using the Arrows framework which provides a systematic way of composing elements and connecting their inputs and outputs. Arrows were introduced to Haskell by John Hughes [5] and later refined by Ross Paterson [9] who added the loop combinator for encoding diagrams with cycles and developed a special notation to aid writing clear programs using arrows. To use these facilities we need to implement three fundamental operations: arr :: (a -> b) -> Signal a b (>>>) :: Signal a b -> Signal b c -> arrow a c first :: Signal a b -> Signal (a, c) (b, c) Diagrams of the operations are shown in Figure 10. First operation, arr, lifts a pure function to a signal transformer, that is, produces an arrow that does exactly the same thing as the lifted function. We call resulting signal transformers 10

11 a c d e b a b c d e Figure 11: Encoding of acyclic graphs using arrows a v c b loop v Figure 12: The loop combinator pure, because they do nothing except pure calculations to compute the result. The other two operations are for composing arrows. Serial composition operator (>>>) connects output of the first transformer to the input of the second. Operation first creates a transformer which behaves like its argument in the first component of pair and passes through second component unchanged. It turns out that those three operations are sufficient to encode any acyclic graph of widgets. Example of such encoding is explained in Figure 11 where diagram on top is encoded into an expression shown again as a diagram on the bottom. The primitive components are arranged in the order of topological sort so that all edges are oriented from left to right. Dotted rectangles indicate applications of first which are used to bypass primitive components if the edge is directed to a component which occurs later on in the sequence. All of them are joined by the sequential composition operator (>>>) with applications of arr plumbx inserted between them where plumbx are functions that redirect data to correct places. For instance, the one located between first b and first c swaps two components of a pair. plumb2 ~(x, y) = (y, x) Please note that the encoding is not bijective as one graph may be represented in various ways. Full explanation of the technique is presented in [9]. We are also interested in creating programs where interconnections between components form cycles. For this to be possible to express using arrows we need only one more operation loop :: Signal (a, c) (b, c) -> Signal a b which takes a signal transformer acting on pairs and creates a loop on the second component of the pair as shown in Figure 12. To encode a diagram 11

12 with cycles we employ a similar technique as described before, but we enclose whole expression loop which will deliver backward edges to the beginning of the sequence from where they can be routed by the basic technique. As a simple example we show the code for composing the widgets of Figure 8. rec d1 <- textentry -< s d2 <- textentry -< s s <- textmodel "" -< d1 merge d2 returna -< () 3.4 Layout combinators Composition using arrow operations imposes a linear order on the components which we exploit for specifying layout. We will present two basic layout combinators which provide essential hierarchical layout capabilities. The combinators have following signatures vbox :: Signal a b -> Signal a b hbox :: Signal a b -> Signal a b and are responsible for vertical and horizontal layout. Applying a layout combinator to a specific fragment of a GUI specifies relative layout of components of that GUI and is completely transparent otherwise. A component is under influence of the closest enclosing layout operator which makes creating complex hierarchical layouts a matter of nested applications of the combinators. 3.5 Model-view-controller revisited In Section 2.4 we showed a text entry and an external data model that cooperate by sending change notifications back and forth between each other. Specifically, the text entry was being notified of changes in the model by a signal of type (String, Sparse TextDelta). The view has access to the whole text buffer given in the first component, but is also allowed to use the discrete signal. It is used for advertising changes to avoid doing unnecessary work when the data doesn t change and to apply changes that arrive with notifications instead of reading the whole buffer. However, there are two things that could go wrong with this representation: The programmer could replace one of the components of the pair to some other value violating the assertion that the second component describes the change of the first; or he could redirect the output of another text model to the entry at some point and, because of lack of the event on the discrete signal indicating changes, the view would not notice the change and not update its display. To address these problems, we present an opaque datatype which will be used in the place of the pair (a, Sparse d). data CompoundData a d where type a denotes data and type d changes. The simplest thing that we can do with CompoundData a d is to extract the data from it. 12

13 extractdata :: CompoundData a d -> a However, if we wanted to benefit from change notification we should use another operation implemented as a signal transformer: data CompoundAction a d = SwapContents a ApplyDelta d getcompoundaction :: Signal (CompoundData a d) (Sparse (CompoundAction a d)) This operation exists to protect a view from wrong interpretations of changes to data. If the source of the data suddenly changes, the operation detects this and outputs an instruction SwapContents which orders the view to completely replace its data. However, in presence of a valid update ApplyDelta is generated. This behaviour is implemented using special markers contained in the CompoundData datatype. 4 Implementation This section describes briefly the internals of the toolkit and how it interacts with the GTK toolkit. Parts of this section that provide intuitive descriptions are intermixed with more technical ones. 4.1 Overview of GTK Before we discuss the implementation, we should outline the style which is used for programming applications based on GTK. GTK is a multi-platform GUI toolkit implemented as a C library which provides a typical imperative programming interface. Programs written on top of GTK are event-driven and their behavior is implemented in callbacks. A callback is a function that is being executed by the toolkit code in response to some event. For instance, if the example from Figure 3 was implemented directly in GTK, when the user would enter something into the first text entry, a callback associated with the text-changed event of that entry would be launched. This would execute code which would extract the contents of the entry and copy it into the second entry. Typically, control reaches the code written by the programmer of the application for a very brief moment and is returned immediately to the toolkit code either by invoking its functions or by returning from the callback. To combine a library written in Haskell with one written in C special wrapping code is needed. This functionality is provided by the Gtk2Hs library which is a wrapper-library that allows for developing programs using GTK in Haskell. Being a wrapper-library means that Gtk2Hs strictly mirrors the API of GTK in Haskell without adding any high-level abstractions in functional style and that programming using it follows the same imperative style of GTK. A substantial part of our work consists of adjusting the implementation of our functional GUI to cooperate with the imperative approach of GTK. 4.2 Basic version For simplicity, we will start by discussing a basic version of signal transformer which does not support all the features. Conceptually, one calculation step executed on a transformer consists of three phases: 13

14 extract a b post action Figure 13: Graphical sketch of a signal transformer empty extractor v w v arr f empty post-action v >>> w joined post actions first v Figure 14: Arrow operations interfering with extractors and post-actions 1. Extraction of values from the underlying toolkit; 2. Calculation making use of the extracted values from phase 1 and of the explicit input from other parts of the diagram; 3. Execution of post-actions generated by phase 2, which affect the underlying toolkit. Graphical sketch of a signal transformer from a to b is shown in Figure 13. The internal representation include extraction and generating post-action (dotted arrows) but the interface hides them leaving only input and output channels exposed (solid arrows) to the programmer. For example in the case of simpletextentry the three phases are as follows: 1. Extraction of text that is held in the widget; 2. Calculation ignores the explicit (void) input and presents the extracted text as its output; 3. Post-action is empty. Signal transformers which are composite are executed exactly in the same way as simple ones. In this case the extracted values are routed independently to all contained simple transformers, and post-actions are sequenced together to form a composite post-action. Composition of signal transformers with respect to extractors and post-actions is shown in Figure 14 (recall that any diagram can be represented using three primitive operations arr, >>> and first) Technical Details Below we show the type of the function which is used to create basic signal transformers represented by a simpler datatype SignalEval a b. Missing features will be added later be means of an arrow transformer. 14

15 simplesignaleval :: (IO a ) -- extraction -> (a -> a -> (b, IO ())) -- calculation yielding -- value and post-action -> SignalEval a b Using the function forces the right style of programming signal transformers where each calculation step consists of (1) extracting the needed values from underlying imperative toolkit yielding values of type a and (2) performing pure computation that has access to extracted values and input of the transformer (a) which produces the output value (b) and an action (IO ()) which will be run just after the step. Extraction and computation are then together represented as a single function of type a -> IO (b, IO ()) which is hidden in the datatype SignalEval a b. data SignalEval a b = SignalEval (a -> IO (b, IO ())) Composition of signal transformers yields a value of type SignalEval a b with all extracting actions embedded inside and producing final value in addition to a post-action consisting of a sequence of post-actions of all its elements. Code executing one step of the computation is structured as follows: runsignaleval :: SignalEval a b -> a -> IO b runsignaleval (SignalEval v) x = do (y, postaction) <- v x -- execute proper calculation postaction -- execute post-action Being able to execute computation steps in response to events delivered by the underlying GUI toolkit is essential for integrating an imperative GUI toolkit with a functional interface. To realize it we connect each event that requires taking action to a global callback that launches runsignaleval. Subsequently, runsignaleval automatically extracts all the needed values, performs calculations and updates the GUI by executing post-actions. This procedure, however, must be augmented if a signal transformer is a source of a discrete signal. We would like the extraction phase of such signal transformer to yield a flag saying whether the signal should be marked active or not. Since there is no way to ask GTK if a widget is the origin of the event we need to add special logic to each signal transformer that will keep track of whether the event occurred on current execution step or not. This special logic is implemented in a local callback function that is registered to the widget at its creation. Instead of directly triggering the global callback it changes the value of a specially-kept reference to indicate the signal before calling the global callback. This reference will then be read in the extraction phase and will eventually get reset to its default value after the execution of the global callback. 4.3 Dynamic features To represent mutable state enclosed within GUI components an enriched version of the main datatype must be used. Each computation step produces a new version of the structure in addition to ordinary output as shown in Figure 15. After a step the signal transformer is replaced by its new version, that could be called its continuation, and which reflects the change in its state. The interface 15

16 step n step n Figure 15: Stateful signal transformer visible to the programmer remains the same with the additional output hidden. As the simplest example, all stateless signal transformers transmit their own copies as their continuations. Passing continuations also allows for a direct implementation of switching of pure signal transformers because we can simply pass the desired new signal transformer as the continuation. Switching of widgets is more problematic as we need to explicitly register and unregister them in the layout hierarchy. We will, however, omit this detail from our description Double-step implementation The presence of switching combinators implies that a computation step may result in a complete change of a fragment of a GUI. As a consequence, our library may need to issue commands displaying the new widgets immediately after completing the calculation and before a new event arrives. However, displaying some widgets requires knowing the inputs of their signal transformers which in effect forces us to recalculate the whole diagram. Therefore the implementation performs two calculation steps in response to each event: one with the source discrete signal turned on and one with all discrete signals blank. The second calculation step is there to populate all widgets with the right data and cannot cause another switch to occur because no discrete signal could be lit thanks to the restrictions posed on manipulating Sparse a values. We assert that this additional fake step does not change the semantics of our interface, although we do not provide a formal proof for it Details of dynamic implementation To express producing continuations by signal transformers we will use an arrow transformer from the Arrow Template Library data Automaton a b c = Automaton (a b (c, Automaton a b c)) This transformer enriches an arrow type a by creating an arrow type which has the same input (b) but whose output is augmented by a continuation ((c, Automaton a b c)). Therefore our datatype will have a form of type Signal a b = Automaton SignalEval a b 16

17 To signal transformers producing continuations, the global callback handling function must be adapted to use a global reference holding latest version of the GUI which is update after each double-step. 4.4 Implementation of layout and other details Implementing hierarchical layout requires augmenting the main datatype even more. We add one more value to the hidden output of each signal transformer which holds the information about widgets contained inside and can is used by enclosing widgets to actually add the widgets to their lists of children. We do not provide combinators for specifying dynamic layout because it may be specified directly using a simple combination of the switching combinator from Section 2.5 and of ordinary layout combinators. 5 Discussion of implementation During the implementation of our toolkit we made the decision to use arrow transformers instead of a single arrow type in hope that this would lead to cleaner code. However, it is not obvious if this decision was right. On one hand using arrow transformers allows to hide some features of an arrow type from places where it is not used leading to simpler code. On the other hand, the design of our arrow is rather complex and there are cases where we had to cross boundaries of arrow transformers using features of all of them at once which led to ugly results. Furthermore, should we one day decide to implement dynamic optimizations, as outlined in [6], we would be forced to convert to monolithic arrow type. The performance of the library seems satisfactory, although no serious benchmarks have been conducted. Small-scale examples exhibited no noticeable performance disadvantage when compared to pure GTK programs. The most obvious limitation of the library, which also affects all known libraries based on the dataflow model, is the fact that the dataflow diagram must be recomputed completely on each step. This leads to O(n) complexity, with n being the total number of GUI components, even in case of minor updates. Dynamic optimization techniques known to be implemented for Fruit attempt to alleviate this burden, however they seem to be just shaving off the constant factors instead of reducing the complexity. The toolkit supports only one simple version of switching combinator which is intended to serve as a proof of concept, but is not enough to handle all situations. Implementing other types of switching combinators is likely possible using the current design, however it has not been made because of time constraints imposed by the project. 6 Conclusions and future work This work has shown that it is feasible to implement a functional GUI toolkit based on dataflow model on top of an imperative one without losing switching features. Only a limited switching combinator has been implemented to date, however we believe that there are no fundamental obstacles against implementing the general switching combinators. 17

18 Furthermore, we have shown how to express MVC separation in dataflow model elegantly and efficiently by explicitly transmitting the changes to the data between views and the controller. The presented toolkit is far from being a viable alternative to mainstream GUI toolkits; it is of research quality and supports only a very limited set of widgets, yet it looks as a prospective candidate for further development. Apart from adding the support for the remaining GTK widgets and implementing extra switching combinators, there are other areas for improvement. It would be beneficial to implement custom layout engine instead of relying on the one provided by GTK which would make controlling layout easier. It would be also possible to experiment with relaxing the hierarchical layout model. However, custom layout engine would probably require bypassing usual GTK rendering and using some low-level primitives, possibly GTK-engine API. Optimizing the implementation is another broad topic. Two obvious possibilities include static optimization using GHC rewrite rules and dynamic optimization using specially-crafted datatype that explicitly models special cases that are possible to simplify [6]. References [1] Magnus Carlsson and Thomas Hallgren. Fudgets - Purely Functional Processes with applications to Graphical User Interfaces. PhD thesis, Chalmers University of Technology, Gteborg University, [2] Antony Courtney. Modeling User Interfaces in a Functional Language. PhD thesis, Yale University, March [3] Antony Courtney and Conal Elliott. Genuinely functional user interfaces. In Haskell Workshop 01, [4] Conal Elliott and Paul Hudak. Functional reactive animation. Proceedings of the second ACM SIGPLAN international conference on Functional programming, pages , [5] John Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1-3):67 111, [6] Henrik Nilsson. Dynamic optimization for functional reactive programming using generalized algebraic data types. In Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming (ICFP 05), pages 54 65, Tallinn, Estonia, September ACM Press. [7] Henrik Nilsson, Antony Courtney, and John Peterson. Functional reactive programming, continued. In Proceedings of the 2002 ACM SIGPLAN Haskell Workshop (Haskell 02), pages 51 64, Pittsburgh, Pennsylvania, USA, October ACM Press. [8] Sean Parent. A Possible Future of Software Development. Keynote presentation at Library-Centric Software Design Workshop, Slides available at future.pdf. 18

19 [9] Ross Paterson. A new notation for arrows. Proceedings of the sixth ACM SIGPLAN international conference on Functional programming, pages , [10] Bart Robinson. wxfruit: A Practical GUI Toolkit for Functional Reactive Programming, March

Modeling User Interfaces in a Functional Language. Antony Courtney. Zhong Shao Conal Elliott

Modeling User Interfaces in a Functional Language. Antony Courtney. Zhong Shao Conal Elliott Modeling User Interfaces in a Functional Language Antony Courtney Advisor: Committee: Acknowledgement: Paul Hudak John Peterson Zhong Shao Conal Elliott Henrik Nilsson Thesis Thesis: Functional Reactive

More information

CFRP issues: Restart (2)

CFRP issues: Restart (2) ITU FRP 2010 Lecture 2: Yampa: Arrows-based FRP Henrik Nilsson School of Computer Science University of Nottingham, UK Outline CFRP issues Introduction to Yampa Arrows A closer look at Yampa CFRP issues:

More information

The Arrow Calculus (Functional Pearl)

The Arrow Calculus (Functional Pearl) The Arrow Calculus (Functional Pearl) Sam Lindley Philip Wadler Jeremy Yallop University of Edinburgh Abstract We introduce the arrow calculus, a metalanguage for manipulating Hughes s arrows with close

More information

Declarative Programming of Interactive Systems with Grapefruit

Declarative Programming of Interactive Systems with Grapefruit in detail Declarative Programming of Interactive Systems with Brandenburgische Technische Universität Cottbus Cottbus, Germany Software Technology Colloquium at Utrecht Universiteit May 29, 2008 overview

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

The Arpeggigon (1) The Arpeggigon: A Functional Reactive Musical Automaton London Haskell Meetup, The Arpeggigon (2) The Harmonic Table

The Arpeggigon (1) The Arpeggigon: A Functional Reactive Musical Automaton London Haskell Meetup, The Arpeggigon (2) The Harmonic Table The Arpeggigon (1) The Arpeggigon: A Functional Reactive Musical Automaton London Haskell Meetup, 2017-06-28 Software realisation of the reactogon: Henrik Nilsson Functional Programming Laboratory, School

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Chapter 2 Overview of the Design Methodology

Chapter 2 Overview of the Design Methodology Chapter 2 Overview of the Design Methodology This chapter presents an overview of the design methodology which is developed in this thesis, by identifying global abstraction levels at which a distributed

More information

Introduction to Programming, Aug-Dec 2006

Introduction to Programming, Aug-Dec 2006 Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components

More information

Representing Symbolic Reasoning

Representing Symbolic Reasoning Representing Symbolic Reasoning Brian Mastenbrook and Eric Berkowitz 1400 N. Roosevelt Blvd. Schaumburg, IL 60173 chandler@acm.roosevelt.edu eric@cs.roosevelt.edu Abstract Introspection is a fundamental

More information

Towards data-flow oriented workflow systems

Towards data-flow oriented workflow systems Towards data-flow oriented workflow systems Alexander Mattes 1, Annette Bieniusa 1, and Arie Middelkoop 2 1 University of Kaiserslautern 2 vwd Group Abstract. Work flow frameworks have become an integral

More information

The Synchronous Approach (1) The Synchronous Approach (2) The Synchronous Approach (3)

The Synchronous Approach (1) The Synchronous Approach (2) The Synchronous Approach (3) Functional Reactivity: Eschewing the Imperative An Overview of Functional Reactive Programming in the Context of Yampa Henrik Nilsson University of Nottingham, UK The Synchronous Approach (1) The synchronous

More information

AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz

AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz Results obtained by researchers in the aspect-oriented programming are promoting the aim to export these ideas to whole software development

More information

Appendix: Generic PbO programming language extension

Appendix: Generic PbO programming language extension Holger H. Hoos: Programming by Optimization Appendix: Generic PbO programming language extension As explained in the main text, we propose three fundamental mechanisms to be covered by a generic PbO programming

More information

Interactions A link message

Interactions A link message Interactions An interaction is a behavior that is composed of a set of messages exchanged among a set of objects within a context to accomplish a purpose. A message specifies the communication between

More information

Analysis and Design with the Universal Design Pattern

Analysis and Design with the Universal Design Pattern Analysis and Design with the Universal Design Pattern by Koni Buhrer Software Engineering Specialist Rational Software Developing large software systems is notoriously difficult and unpredictable. Software

More information

Background Type Classes (1B) Young Won Lim 6/28/18

Background Type Classes (1B) Young Won Lim 6/28/18 Background Type Classes (1B) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

Chapter 12. UML and Patterns. Copyright 2008 Pearson Addison-Wesley. All rights reserved

Chapter 12. UML and Patterns. Copyright 2008 Pearson Addison-Wesley. All rights reserved Chapter 12 UML and Patterns Copyright 2008 Pearson Addison-Wesley. All rights reserved Introduction to UML and Patterns UML and patterns are two software design tools that can be used within the context

More information

Separating Product Variance and Domain Concepts in the Specification of Software Product Lines

Separating Product Variance and Domain Concepts in the Specification of Software Product Lines Separating Product Variance and Domain Concepts in the Specification of Software Product Lines Pertti Kellomäki Software Systems Laboratory, Tampere University of Technology P.O. Box 553, FIN-33101 Tampere,

More information

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING Wednesady 23 rd March 2016 Afternoon Answer any FOUR questions out of SIX. All

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

More information

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Computational Effects Also known as side effects. A function or expression is said to have a side effect if,

More information

Intro to Haskell Notes: Part 5

Intro to Haskell Notes: Part 5 Intro to Haskell Notes: Part 5 Adrian Brasoveanu October 5, 2013 Contents 1 Curried functions and related issues 1 1.1 Curried functions......................................... 1 1.2 Partially applied

More information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

RAISE in Perspective

RAISE in Perspective RAISE in Perspective Klaus Havelund NASA s Jet Propulsion Laboratory, Pasadena, USA Klaus.Havelund@jpl.nasa.gov 1 The Contribution of RAISE The RAISE [6] Specification Language, RSL, originated as a development

More information

Denotational Semantics. Domain Theory

Denotational Semantics. Domain Theory Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning

More information

A Brief Haskell and GHC Refresher

A Brief Haskell and GHC Refresher A Brief Haskell and GHC Refresher Henrik Nilsson and Neil Sculthorpe School of Computer Science University of Nottingham 24th September 2013 1 Introduction The purpose of this document is to give you quick

More information

Incompatibility Dimensions and Integration of Atomic Commit Protocols

Incompatibility Dimensions and Integration of Atomic Commit Protocols The International Arab Journal of Information Technology, Vol. 5, No. 4, October 2008 381 Incompatibility Dimensions and Integration of Atomic Commit Protocols Yousef Al-Houmaily Department of Computer

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1 What is a Design Pattern? Each pattern Describes a problem which occurs over and over again in our environment,and then describes the core of the problem Novelists, playwrights and other writers rarely

More information

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré Hoare Logic COMP2600 Formal Methods for Software Engineering Rajeev Goré Australian National University Semester 2, 2016 (Slides courtesy of Ranald Clouston) COMP 2600 Hoare Logic 1 Australian Capital

More information

Programming with Math and Logic

Programming with Math and Logic .. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) A process has a: 1) A) pronoun label B) noun phrase label C) verb phrase label D) adjective

More information

Refinement and Optimization of Streaming Architectures. Don Batory and Taylor Riché Department of Computer Science University of Texas at Austin

Refinement and Optimization of Streaming Architectures. Don Batory and Taylor Riché Department of Computer Science University of Texas at Austin Refinement and Optimization of Streaming Architectures Don Batory and Taylor Riché Department of Computer Science University of Texas at Austin 1 Introduction Model Driven Engineering (MDE) is paradigm

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Software Service Engineering

Software Service Engineering Software Service Engineering Lecture 4: Unified Modeling Language Doctor Guangyu Gao Some contents and notes selected from Fowler, M. UML Distilled, 3rd edition. Addison-Wesley Unified Modeling Language

More information

Minsoo Ryu. College of Information and Communications Hanyang University.

Minsoo Ryu. College of Information and Communications Hanyang University. Software Reuse and Component-Based Software Engineering Minsoo Ryu College of Information and Communications Hanyang University msryu@hanyang.ac.kr Software Reuse Contents Components CBSE (Component-Based

More information

Sub- PPL Unit-I Class-SE Comp

Sub- PPL Unit-I Class-SE Comp 1. We describe the basic concepts for structuring large programs (encapsulation, interfaces, information hiding) and the mechanisms provided by languages to support it (packaging, separate compilation).

More information

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via  by Friday, Mar. 18, 2016 Math 304 - Dr. Miller - Constructing in Sketchpad (tm) - Due via email by Friday, Mar. 18, 2016 As with our second GSP activity for this course, you will email the assignment at the end of this tutorial

More information

Business Activity. predecessor Activity Description. from * successor * to. Performer is performer has attribute.

Business Activity. predecessor Activity Description. from * successor * to. Performer is performer has attribute. Editor Definition Language and Its Implementation Audris Kalnins, Karlis Podnieks, Andris Zarins, Edgars Celms, and Janis Barzdins Institute of Mathematics and Computer Science, University of Latvia Raina

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Question 1: What is a code walk-through, and how is it performed?

Question 1: What is a code walk-through, and how is it performed? Question 1: What is a code walk-through, and how is it performed? Response: Code walk-throughs have traditionally been viewed as informal evaluations of code, but more attention is being given to this

More information

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics CONVENTIONAL EXECUTABLE SEMANTICS Grigore Rosu CS522 Programming Language Semantics Conventional Semantic Approaches A language designer should understand the existing design approaches, techniques and

More information

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Submitted to the Onward track of OOPSLA-03 ABSTRACT. Keywords

Submitted to the Onward track of OOPSLA-03 ABSTRACT. Keywords GUI Environments for Functional Languages Daniel J. Pless & George F. Luger University of New Mexico, Computer Science Ferris Engineering Center Albuquerque, NM 87131 (505) 277-9424 {dpless,luger}@cs.unm.edu

More information

Software Reuse and Component-Based Software Engineering

Software Reuse and Component-Based Software Engineering Software Reuse and Component-Based Software Engineering Minsoo Ryu Hanyang University msryu@hanyang.ac.kr Contents Software Reuse Components CBSE (Component-Based Software Engineering) Domain Engineering

More information

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics CONVENTIONAL EXECUTABLE SEMANTICS Grigore Rosu CS422 Programming Language Semantics Conventional Semantic Approaches A language designer should understand the existing design approaches, techniques and

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Test-Driven Development (TDD)

Test-Driven Development (TDD) Test-Driven Development (TDD) CS 4501 / 6501 Software Testing [Lasse Koskela, Test Driven, Chapters 2-3] 1 Agile Airplane Testing Test harness: Appearance matches Color coding in place Fly 6ft (or 2m)

More information

Design Patterns Design patterns advantages:

Design Patterns Design patterns advantages: Design Patterns Designing object-oriented software is hard, and designing reusable object oriented software is even harder. You must find pertinent objects factor them into classes at the right granularity

More information

Superficial the concepts

Superficial the concepts Superficial the concepts Superficial is a fresh approach to the design and coding of interactive applications, in particular those with graphical user interfaces (GUIs). Superficial provides a conceptual

More information

2. BOOLEAN ALGEBRA 2.1 INTRODUCTION

2. BOOLEAN ALGEBRA 2.1 INTRODUCTION 2. BOOLEAN ALGEBRA 2.1 INTRODUCTION In the previous chapter, we introduced binary numbers and binary arithmetic. As you saw in binary arithmetic and in the handling of floating-point numbers, there is

More information

Homework 1: Functional Programming, Haskell

Homework 1: Functional Programming, Haskell Com S 541 Programming Languages 1 September 25, 2005 Homework 1: Functional Programming, Haskell Due: problems 1 and 3, Thursday, September 1, 2005; problems 4-9, Thursday, September 15, 2005; remaining

More information

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences]

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences] GADTs Advanced functional programming - Lecture 7 Wouter Swierstra and Alejandro Serrano 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree

More information

Functional Programming Language Haskell

Functional Programming Language Haskell Functional Programming Language Haskell Mohammed Aslam CIS 24 Prof. Kopec Presentation: 03 Date: 05/05/2003 Haskell is a general purpose, purely functional programming language named after the logician

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Distributed minimum spanning tree problem

Distributed minimum spanning tree problem Distributed minimum spanning tree problem Juho-Kustaa Kangas 24th November 2012 Abstract Given a connected weighted undirected graph, the minimum spanning tree problem asks for a spanning subtree with

More information

6.001 Notes: Section 1.1

6.001 Notes: Section 1.1 6.001 Notes: Section 1.1 Slide 1.1.1 This first thing we need to do is discuss the focus of 6.001. What is this course all about? This seems quite obvious -- this is a course about computer science. But

More information

Functional Fibonacci to a Fast FPGA

Functional Fibonacci to a Fast FPGA Functional Fibonacci to a Fast FPGA Stephen A. Edwards Columbia University, Department of Computer Science Technical Report CUCS-010-12 June 2012 Abstract Through a series of mechanical transformation,

More information

(Refer Slide Time 6:48)

(Refer Slide Time 6:48) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

More information

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences]

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences] GADTs AFP Summer School Alejandro Serrano 1 Today s lecture Generalized algebraic data types (GADTs) 2 A datatype data Tree a = Leaf Node (Tree a) a (Tree a) This definition introduces: 3 A datatype data

More information

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN NOTES ON OBJECT-ORIENTED MODELING AND DESIGN Stephen W. Clyde Brigham Young University Provo, UT 86402 Abstract: A review of the Object Modeling Technique (OMT) is presented. OMT is an object-oriented

More information

THE BCS PROFESSIONAL EXAMINATION BCS Level 5 Diploma in IT September 2017 EXAMINERS REPORT

THE BCS PROFESSIONAL EXAMINATION BCS Level 5 Diploma in IT September 2017 EXAMINERS REPORT THE BCS PROFESSIONAL EXAMINATION BCS Level 5 Diploma in IT September 2017 EXAMINERS REPORT Object Oriented Programming Question A1 a) Explain the terms abstract data type and encapsulation and describe

More information

Category Theory in Ontology Research: Concrete Gain from an Abstract Approach

Category Theory in Ontology Research: Concrete Gain from an Abstract Approach Category Theory in Ontology Research: Concrete Gain from an Abstract Approach Markus Krötzsch Pascal Hitzler Marc Ehrig York Sure Institute AIFB, University of Karlsruhe, Germany; {mak,hitzler,ehrig,sure}@aifb.uni-karlsruhe.de

More information

Design Patterns IV Structural Design Patterns, 1

Design Patterns IV Structural Design Patterns, 1 Structural Design Patterns, 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 Class Object Department of Computer Science The Australian National University 18.1 1 2 Class Object

More information

Monads in Haskell. Nathanael Schilling. December 12, 2014

Monads in Haskell. Nathanael Schilling. December 12, 2014 Monads in Haskell Nathanael Schilling December 12, 2014 Abstract In Haskell, monads provide a mechanism for mapping functions of the type a -> m b to those of the type m a -> m b. This mapping is dependent

More information

Real-Time Coordination in Distributed Multimedia Systems

Real-Time Coordination in Distributed Multimedia Systems Real-Time Coordination in Distributed Multimedia Systems Theophilos A. Limniotes and George A. Papadopoulos Department of Computer Science University of Cyprus 75 Kallipoleos Str, P.O.B. 20537 CY-1678

More information

Monads. Mark Hills 6 August Department of Computer Science University of Illinois at Urbana-Champaign

Monads. Mark Hills 6 August Department of Computer Science University of Illinois at Urbana-Champaign Monads Mark Hills mhills@cs.uiuc.edu Department of Computer Science University of Illinois at Urbana-Champaign 6 August 2009 Hills Monads 1 / 19 Overview Overview Hills Monads 2 / 19 Why Monads? Overview

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

Unified Modeling Language

Unified Modeling Language Unified Modeling Language Modeling Applications using Language Mappings Programmer s Reference Manual How to use this Reference Card: The consists of a set of fundamental modeling elements which appear

More information

Structural polymorphism in Generic Haskell

Structural polymorphism in Generic Haskell Structural polymorphism in Generic Haskell Andres Löh andres@cs.uu.nl 5 February 2005 Overview About Haskell Genericity and other types of polymorphism Examples of generic functions Generic Haskell Overview

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

Functional Reactive Programming. Yampa: Functional Reactive Programming for Systems with Dynamic Structure. Related languages. Reactive programming

Functional Reactive Programming. Yampa: Functional Reactive Programming for Systems with Dynamic Structure. Related languages. Reactive programming Functional Reactive Programming Yampa: Functional Reactive Programming for Systems with Dynamic Structure Henrik Nilsson University of Nottingham, UK Yampa: FunctionalReactive Programming for Systems with

More information

1 Delimited continuations in Haskell

1 Delimited continuations in Haskell 1 Delimited continuations in Haskell This section describes programming with delimited control in Haskell. Delimited control, like its instance, exceptions, is an effect. Therefore, we have to use monads.

More information

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi Lecture - 8 Consistency and Redundancy in Project networks In today s lecture

More information

Lecture 9: Group Communication Operations. Shantanu Dutt ECE Dept. UIC

Lecture 9: Group Communication Operations. Shantanu Dutt ECE Dept. UIC Lecture 9: Group Communication Operations Shantanu Dutt ECE Dept. UIC Acknowledgement Adapted from Chapter 4 slides of the text, by A. Grama w/ a few changes, augmentations and corrections Topic Overview

More information

Basic Steps for Creating an Application with the ArcGIS Server API for JavaScript

Basic Steps for Creating an Application with the ArcGIS Server API for JavaScript Chapter 4: Working with Maps and Layers Now that you have a taste of ArcGIS Server and the API for JavaScript it s time to actually get to work and learn how to build some great GIS web applications! The

More information

Automating Unpredictable Processes:

Automating Unpredictable Processes: Automating Unpredictable Processes: Building Responsive Apps using Business Rules By Carl Hewitt, Chief Architect, Decisions and Heath Oderman, CTO, Decisions Copyright 2016 Building Responsive Apps: Comparing

More information

Semantics of COW. July Alex van Oostenrijk and Martijn van Beek

Semantics of COW. July Alex van Oostenrijk and Martijn van Beek Semantics of COW /; ;\ \\ // /{_\_/ `'\ \ (o) (o } / :--',-,'`@@@@@@@@ @@@@@@ \_ ` \ ;:( @@@@@@@@@ @@@ \ (o'o) :: ) @@@@ @@@@@@,'@@( `====' Moo! :: : @@@@@: @@@@ `@@@: :: \ @@@@@: @@@@@@@) ( '@@@' ;; /\

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns Structural Design Patterns, 1 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 2 3 Department of Computer Science The Australian National University 4 18.1 18.2 GoF Structural

More information

An Audio View of (L A )TEX Documents Part II

An Audio View of (L A )TEX Documents Part II T. V. Raman Digital Equipment Corporation Cambridge Research Lab One Kendall Square, Building 650 Cambridge, MA 02139, USA Email: raman@crl.dec.com URL: http://www.cs.cornell.edu/info/people/raman/raman.html

More information

Concept as a Generalization of Class and Principles of the Concept-Oriented Programming

Concept as a Generalization of Class and Principles of the Concept-Oriented Programming Computer Science Journal of Moldova, vol.13, no.3(39), 2005 Concept as a Generalization of Class and Principles of the Concept-Oriented Programming Alexandr Savinov Abstract In the paper we describe a

More information

Multi-paradigm Declarative Languages

Multi-paradigm Declarative Languages Michael Hanus (CAU Kiel) Multi-paradigm Declarative Languages ICLP 2007 1 Multi-paradigm Declarative Languages Michael Hanus Christian-Albrechts-University of Kiel Programming Languages and Compiler Construction

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Hello, world! 206 TUGboat, Volume 31 (2010), No. 2. resulting in: Drawing structured diagrams with SDDL Mathieu Bourgeois and Roger Villemaire

Hello, world! 206 TUGboat, Volume 31 (2010), No. 2. resulting in: Drawing structured diagrams with SDDL Mathieu Bourgeois and Roger Villemaire 206 TUGboat, Volume 31 (2010), No. 2 Abstract We present SDDL, a Structured Diagram Description Language aimed at producing graphical representations for discrete mathematics and computer science. SDDL

More information

Linearizable Iterators

Linearizable Iterators Linearizable Iterators Supervised by Maurice Herlihy Abstract Petrank et. al. [5] provide a construction of lock-free, linearizable iterators for lock-free linked lists. We consider the problem of extending

More information

Program Calculus Calculational Programming

Program Calculus Calculational Programming Program Calculus Calculational Programming National Institute of Informatics June 21 / June 28 / July 5, 2010 Program Calculus Calculational Programming What we will learn? Discussing the mathematical

More information

The design of a programming language for provably correct programs: success and failure

The design of a programming language for provably correct programs: success and failure The design of a programming language for provably correct programs: success and failure Don Sannella Laboratory for Foundations of Computer Science School of Informatics, University of Edinburgh http://homepages.inf.ed.ac.uk/dts

More information

Value Recursion in Monadic Computations

Value Recursion in Monadic Computations Value Recursion in Monadic Computations Levent Erkök OGI School of Science and Engineering, OHSU Advisor: John Launchbury June 24th, 2002 Outline Recursion and effects Motivating examples Value recursion

More information

Behavior Programming Language and Automated Code Generation for Agent Behavior Control

Behavior Programming Language and Automated Code Generation for Agent Behavior Control Behavior Programming Language and Automated Code Generation for Agent Behavior Control Thuc Vu, Manuela Veloso tdv@andrew.cmu.edu, mmv@cs.cmu.edu Carnegie Mellon University 5000 Forbes Avenue Pittsburgh,

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

More information

Side Effects (3A) Young Won Lim 1/13/18

Side Effects (3A) Young Won Lim 1/13/18 Side Effects (3A) Copyright (c) 2016-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

From Craft to Science: Rules for Software Design -- Part II

From Craft to Science: Rules for Software Design -- Part II From Craft to Science: Rules for Software Design -- Part II by Koni Buhrer Software Engineering Specialist Rational Software Developing large software systems is notoriously difficult and unpredictable.

More information

Programming Language Pragmatics

Programming Language Pragmatics Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information