Difference between revisions of "PropLang"

From HaskellWiki
Jump to navigation Jump to search
(Categorize)
 
(11 intermediate revisions by one other user not shown)
Line 1: Line 1:
  +
[[Category:User interfaces]] [[Category:Proposals]] [[Category:Libraries]]
A design for a GUI library which is more like Haskell and less like C.
+
A design for a GUI library which is more like Haskell and less like C. To be written over Gtk2Hs.
   
 
Link: http://www.cse.unsw.edu.au/~chak/haskell/ports/
 
Link: http://www.cse.unsw.edu.au/~chak/haskell/ports/
Line 5: Line 6:
 
== Thoughts by ==
 
== Thoughts by ==
   
  +
Neil Mitchell, some patches from Joachim Breitner, discussions and help from Duncan Coutts
Neil Mitchell
 
   
  +
For a darcs repo see: http://www.cs.york.ac.uk/fp/darcs/proplang/
== The Var concept ==
 
   
  +
In particular check out Sample.hs, I am particularly proud of the word count:
This is the low level stuff, on which the library will be built
 
   
 
sb!text =< with1 (txt!text) (\x ->
data Var a = ...
 
  +
"Word count: " ++ show (length $ words x))
data Notify
 
   
  +
== Overview ==
get :: Var a -> IO a
 
set :: Var a -> a -> IO ()
 
addNotify :: Var a -> IO () -> IO Notify
 
remNotify :: Notify -> IO ()
 
   
  +
There are events, you can register to be notified when an event fires by doing
newVar :: a -> IO (Var a)
 
   
  +
event += handler
== Object layering ==
 
   
  +
There are variables, which have events which fire, and a value which you can set and get.
textBox-text -< "test"
 
filename <- newVar Nothing
 
addNotify filename hatCover
 
lbl-text =< with filename $ \x ->
 
case x of
 
Nothing -> "Select a file"
 
Just x -> "Loaded: " ++ x
 
   
 
variable <- newVar "value"
  +
variable += handler
  +
variable -< "value"
  +
x <- getVal variable
   
  +
There are objects, objects have properties. A property is just a variable.
where
 
   
  +
window!text += handler
(-) :: GtkObject -> GtkProp -> Var a -- ignoring lots of details here
 
  +
window!text -< "Titlebar text"
(-<) :: Var a -> a -> IO ()
 
(=<) :: Var a -> Action a -> IO ()
 
   
  +
There are bindings which relate variables.
with :: Var a -> (a -> b) -> Action b
 
  +
  +
-- the window text is the variable
  +
window!text =<= variable
  +
-- the window text is the variable, but upppercase
  +
window!text =< with1 variable (map toUpper)
  +
-- combine the two texts to create the window text
  +
window!text =< with2 variable1 variable2 (++)
  +
  +
If any of the values on the RHS of a binding change, then the LHS is updated.

Latest revision as of 21:21, 23 June 2007

A design for a GUI library which is more like Haskell and less like C. To be written over Gtk2Hs.

Link: http://www.cse.unsw.edu.au/~chak/haskell/ports/

Thoughts by

Neil Mitchell, some patches from Joachim Breitner, discussions and help from Duncan Coutts

For a darcs repo see: http://www.cs.york.ac.uk/fp/darcs/proplang/

In particular check out Sample.hs, I am particularly proud of the word count:

sb!text =< with1 (txt!text) (\x ->
    "Word count: " ++ show (length $ words x))

Overview

There are events, you can register to be notified when an event fires by doing

event += handler

There are variables, which have events which fire, and a value which you can set and get.

variable <- newVar "value"
variable += handler
variable -< "value"
x <- getVal variable

There are objects, objects have properties. A property is just a variable.

window!text += handler
window!text -< "Titlebar text"

There are bindings which relate variables.

-- the window text is the variable
window!text =<= variable
-- the window text is the variable, but upppercase
window!text =< with1 variable (map toUpper)
-- combine the two texts to create the window text
window!text =< with2 variable1 variable2 (++)

If any of the values on the RHS of a binding change, then the LHS is updated.