Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
WxHaskell/Quick start
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Types ==== A typical wxHaskell program imports the <tt>Graphics.UI.WX</tt> library. If you need to access specific wxWidgets functionality, you would also import the lower level <tt>Graphics.UI.WXCore</tt> library. The <tt>main</tt> function uses <tt>start</tt> to start our GUI. The function <tt>start</tt> initializes the GUI framework with the provided argument and starts the window event loop until the application quits or when all top-level windows are closed. The GUI itself is described with the following functions: <pre>frame  ::             [Prop (Frame ())] -> IO (Frame ()) button :: Window a -> [Prop (Button ())] -> IO (Button ()) text   :: Attr (Window a) String layout :: Attr (Frame a)  Layout (:=)   :: Attr w a -> a -> Prop w set    :: w -> [Prop w] -> IO () command:: Event (Control a) (IO ()) on     :: Event w a -> Attr w a widget :: Window a -> Layout</pre> Actually, some of these functions have (even) more general types β you can use the <tt>:t</tt> command in GHCi to see them. The types <tt>Frame ()</tt> and <tt>Button ()</tt> denote graphical objects. These objects can have ''properties''. When an object is created we can supply an initial list of properties but we can also set them later using <tt>set</tt>. The type of properties for frames are <tt>Prop (Frame ())</tt> and for buttons <tt>Prop (Button ())</tt>. Properties are created by combining ''attributes'' with values. Examples of attributes are <tt>text</tt> and <tt>layout</tt>. An attribute of type <tt>Attr w a</tt> applies to objects of type <tt>w</tt> and values of type <tt>a</tt>. Values can be assigned to attributes using the <tt>(:=)</tt> operator. You can find out more about attributes in the haddock documentation for the modules [http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Attributes.html WX.Attributes] and [http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Classes.html WX.Classes]. Somewhat special attributes are ''events''. An event of type <tt>Event w a</tt> can be transformed into an attribute <tt>Attr w a</tt> using <tt>on</tt>. The value of an event attribute is normally an <tt>IO</tt> action that is executed when the event happens. Find out more about events in the haddock documentation for [http://hackage.haskell.org/packages/archive/wx/latest/doc/html/Graphics-UI-WX-Events.html WX.Events] and the lower level [http://hackage.haskell.org/packages/archive/wxcore/latest/doc/html/Graphics-UI-WXCore-Events.html WXCore.Events] Since wxHaskell is based on an object-oriented framework, we also encode inheritance. The extra type parameter of objects encodes the inheritance relationship. When the parameter of an object is unit <tt>()</tt>, it denotes an object of that exact class. When the parameter is a type variable <tt>a</tt>, it denotes any object that is instance of that class. For example, both the <tt>frame</tt> and <tt>button</tt> functions return precisely a frame or button and use a <tt>()</tt> type parameter. However, the <tt>text</tt> attribute applies to any kind of window, including frames and buttons, and has a <tt>Window a</tt> as its argument. We can now use the <tt>text</tt> attribute for example for both frames and buttons. In wxHaskell, this works since a <tt>Frame ()</tt> is actually a type synonym for <tt>Window (CFrame ())</tt> and can thus be passed where a <tt>Window a</tt> is expected. The same hold for a <tt>Button ()</tt> that is a synonym for <tt>Control (CButton ())</tt> that is again a synonym for <tt>Window (CControl (CButton ()))</tt>.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width