We have so far seen how to create user interface components for displaying text and graphics. But how do we actually represent these components in Haggis? The common element across all types of user interface component is that they need to be responsive to commands and requests from the window system, e.g., a component can be told to resize to double its size. In Haggis, we explicitly this commonality using the type DisplayHandle. For instance, the Glyph creating function, glyph, has type
glyph :: Picture -> Component (Glyph, DisplayHandle)
Given a picture to display, the glyph function returns a pair of handles. These handles have a similar function to the file handles in the Haskell 1.3 I/O model where opening a file returns a handle that is then used to read and write bytes to the opened file. The glyph function returns a pair of handles, the DisplayHandle being the handle to the user interface virtual `device'. It is used to communicate system commands to the Glyph such as resize, redisplay etc. The other handle, the Glyph handle represent the application view of the instance created by glyph. It is for example used to change the current Picture to display:
setPicture :: Glyph -> Picture -> IO ()
This scheme is uniformly used by all functions that create user interface components in Haggis, returning a user interface handle, the DisplayHandle, and a handle to the application object they represent. By making an explicit separation between the application handle and the user interface part of a component, the concerns of the user interface and the application can be cleanly separated. For instance, a set of DisplayHandles coming from different user interface components such as a Glyph and a slider, say, can be stored in data structures and manipulated uniformly by layout combinators (more on this later).