[GUI] I love GIO.

Dean Herington heringto@cs.unc.edu
Tue, 11 Feb 2003 09:23:18 -0500


--------------10897D92C561B59651212440
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Warning about the use of (:=): This symbol has been proposed by John
Hughes for use in some future version of Haskell to distinguish
monomorphic and polymorphic `let` constructs.  (See, for example,
http://www.math.chalmers.se/~rjmh/Globals.ps , section 6.)  You might
prefer to choose a different symbol, such as (:==) or (::=).

Dean


Daan Leijen wrote:

> >  2. The := operator.
> >  The =: function should say "assign to this property".  Is seems to
> be the
> > wrong way round. Is it possible to use the constructor := , or is
> this
> > conceptionally difficult?Great plan. I tried it in my upcoming
> wxWindows-GIO library, and foundthat I needed existential types. Not a
> problem since we are GHCdependent anyway :-)  (well, maybe not, NHC is
> getting really good these days).Anyway, I defined:
>
> data Attr w a  = Attr (w -> IO a) (w -> a -> IO ())  -- getter and setter
>
> data Prop w    = forall a. (:=) (Attr w a) a         -- := is a constructor
>
> set :: w -> [Prop w] -> IO ()
> set w props
>   = mapM_ setProp props
>   where
>     setProp ((Attr getter setter) := x)
>       = setter w x
>
> get :: w -> Attr w a -> IO a
> get w (Attr getter setter)
>   = getter w
>
> -- example of an attribute, works for any kind of (wxWindows) Frame
> title :: Attr (Frame a) String
> title
>   = Attr (\w    -> w # frameGetTitle)
>          (\w x  -> w # frameSetTitle x)
>
> ...
>
> gui = do ...
>          set frame [title := "hi there"]
>
>
> Really nice!, thanks for sparking the idea. Nice application of
> existential types too.

--------------10897D92C561B59651212440
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Warning about the use of (:=): This symbol has been proposed by John Hughes
for use in some future version of Haskell to distinguish monomorphic and
polymorphic `let` constructs.&nbsp; (See, for example, <a href="http://www.math.chalmers.se/~rjmh/Globals.ps">http://www.math.chalmers.se/~rjmh/Globals.ps</a>
, section 6.)&nbsp; You might prefer to choose a different symbol, such
as (:==) or (::=).
<p>Dean
<br>&nbsp;
<p>Daan Leijen wrote:
<blockquote TYPE=CITE><font face="Arial"><font size=-1>>&nbsp; 2. The :=
operator.</font></font>
<br><font face="Arial"><font size=-1>>&nbsp; The =: function should say
"assign to this property".&nbsp; Is seems to be the</font></font>
<br><font face="Arial"><font size=-1>> wrong way round. Is it possible
to use the constructor := , or is this</font></font>
<br><font face="Arial"><font size=-1>> conceptionally difficult?</font></font><font face="Arial"><font size=-1>Great
plan. I tried it in my upcoming wxWindows-GIO library, and found</font></font><font face="Arial"><font size=-1>that
I needed existential types. Not a problem since we are GHC</font></font><font face="Arial"><font size=-1>dependent
anyway :-)&nbsp; (well, maybe not, NHC is getting really good these days).</font></font><font face="Arial"><font size=-1>Anyway,
I defined:</font></font>
<pre>data Attr w a&nbsp; = Attr (w -> IO a) (w -> a -> IO ())&nbsp; -- getter and setter</pre>

<pre>data Prop w&nbsp;&nbsp;&nbsp; = forall a. (:=) (Attr w a) a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- := is a constructor</pre>

<pre>set :: w -> [Prop w] -> IO ()
set w props
&nbsp; = mapM_ setProp props
&nbsp; where
&nbsp;&nbsp;&nbsp; setProp ((Attr getter setter) := x)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = setter w x</pre>

<pre>get :: w -> Attr w a -> IO a
get w (Attr getter setter)
&nbsp; = getter w</pre>

<pre>-- example of an attribute, works for any kind of (wxWindows) Frame
title :: Attr (Frame a) String
title
&nbsp; = Attr (\w&nbsp;&nbsp;&nbsp; -> w # frameGetTitle)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (\w x&nbsp; -> w # frameSetTitle x)</pre>

<pre>...</pre>

<pre>gui = do ...
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set frame [title := "hi there"]</pre>
&nbsp;
<br><font face="Arial"><font size=-1>Really nice!, thanks for sparking
the idea. Nice application of existential types too.</font></font></blockquote>
</html>

--------------10897D92C561B59651212440--