[GUI] I love GIO.

Daan Leijen daanleijen@xs4all.nl
Wed, 12 Feb 2003 20:50:35 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0049_01C2D2D8.641D5CD0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


  Warning about the use of (:=3D): 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 (:=3D=3D) or (::=3D).=20

Thanks for mentioning this. However, (:=3D) is a rather attractive =
constructor to use
and I wonder if a monomorphic binding is used enoug to justify taking =
another operator away.

It might be better after all to have a family of "let" bindings in a =
future haskell:
let    -- lazy bindinglet!   -- strict bindinglet$   -- speculative =
binding  (ie. try operationally strictly but maintain lazy =
semantics)let#   -- monomorphic binding ?...

-- Daan.


Dean=20
 =20
  Daan Leijen wrote:=20

    >  2. The :=3D operator.=20
    >  The =3D: function should say "assign to this property".  Is seems =
to be the=20
    > wrong way round. Is it possible to use the constructor :=3D , or =
is this=20
    > 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:=20
data Attr w a  =3D Attr (w -> IO a) (w -> a -> IO ())  -- getter and =
setterdata Prop w    =3D forall a. (:=3D) (Attr w a) a         -- :=3D =
is a constructorset :: w -> [Prop w] -> IO ()
set w props
  =3D mapM_ setProp props
  where
    setProp ((Attr getter setter) :=3D x)
      =3D setter w xget :: w -> Attr w a -> IO a
get w (Attr getter setter)
  =3D getter w-- example of an attribute, works for any kind of =
(wxWindows) Frame
title :: Attr (Frame a) String
title
  =3D Attr (\w    -> w # frameGetTitle)
         (\w x  -> w # frameSetTitle x)...gui =3D do ...
         set frame [title :=3D "hi there"] =20
    Really nice!, thanks for sparking the idea. Nice application of =
existential types too.
------=_NextPart_000_0049_01C2D2D8.641D5CD0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV>Warning about the use of (:=3D): This symbol has been proposed by =
John=20
  Hughes for use in some future version of Haskell to distinguish =
monomorphic=20
  and polymorphic `let` constructs.&nbsp; (See, for example, <A=20
  =
href=3D"http://www.math.chalmers.se/~rjmh/Globals.ps">http://www.math.cha=
lmers.se/~rjmh/Globals.ps</A>=20
  , section 6.)&nbsp; You might prefer to choose a different symbol, =
such as=20
  (:=3D=3D) or (::=3D). </DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>Thanks for mentioning this. =
However, (:=3D)=20
is a&nbsp;rather attractive constructor to use</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>and I wonder if a monomorphic =
binding is=20
used enoug to justify taking another operator away.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>It might be better after all =
to have a=20
family of "let" bindings in a future haskell:</FONT></DIV><PRE =
dir=3Dltr>let&nbsp;&nbsp;&nbsp; -- lazy =
binding<BR>let!&nbsp;&nbsp;&nbsp;-- strict binding<BR>let$&nbsp;&nbsp; =
-- speculative binding&nbsp; (ie. try operationally strictly but =
maintain lazy semantics)<BR>let#&nbsp;&nbsp; -- monomorphic binding =
?</PRE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>...</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>-- Daan.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr>Dean <BR>&nbsp; </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <P>Daan Leijen wrote:=20
  <BLOCKQUOTE TYPE=3D"CITE"><FONT face=3DArial><FONT =
size=3D-1>&gt;&nbsp; 2. The :=3D=20
    operator.</FONT></FONT> <BR><FONT face=3DArial><FONT =
size=3D-1>&gt;&nbsp; The =3D:=20
    function should say "assign to this property".&nbsp; Is seems to be=20
    the</FONT></FONT> <BR><FONT face=3DArial><FONT size=3D-1>&gt; wrong =
way round.=20
    Is it possible to use the constructor :=3D , or is =
this</FONT></FONT>=20
    <BR><FONT face=3DArial><FONT size=3D-1>&gt; conceptionally=20
    difficult?</FONT></FONT><FONT face=3DArial><FONT size=3D-1>Great =
plan. I tried=20
    it in my upcoming wxWindows-GIO library, and =
found</FONT></FONT><FONT=20
    face=3DArial><FONT size=3D-1>that I needed existential types. Not a =
problem=20
    since we are GHC</FONT></FONT><FONT face=3DArial><FONT =
size=3D-1>dependent=20
    anyway :-)&nbsp; (well, maybe not, NHC is getting really good these=20
    days).</FONT></FONT><FONT face=3DArial><FONT size=3D-1>Anyway, I=20
    defined:</FONT></FONT> <PRE>data Attr w a&nbsp; =3D Attr (w -&gt; IO =
a) (w -&gt; a -&gt; IO ())&nbsp; -- getter and setter</PRE><PRE>data =
Prop w&nbsp;&nbsp;&nbsp; =3D forall a. (:=3D) (Attr w a) =
a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- :=3D is a =
constructor</PRE><PRE>set :: w -&gt; [Prop w] -&gt; IO ()
set w props
&nbsp; =3D mapM_ setProp props
&nbsp; where
&nbsp;&nbsp;&nbsp; setProp ((Attr getter setter) :=3D x)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D setter w x</PRE><PRE>get :: w -&gt; =
Attr w a -&gt; IO a
get w (Attr getter setter)
&nbsp; =3D getter w</PRE><PRE>-- example of an attribute, works for any =
kind of (wxWindows) Frame
title :: Attr (Frame a) String
title
&nbsp; =3D Attr (\w&nbsp;&nbsp;&nbsp; -&gt; w # frameGetTitle)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (\w x&nbsp; -&gt; w # =
frameSetTitle x)</PRE><PRE>...</PRE><PRE>gui =3D do ...
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set frame [title :=3D =
"hi there"]</PRE>&nbsp;=20
    <BR><FONT face=3DArial><FONT size=3D-1>Really nice!, thanks for =
sparking the=20
    idea. Nice application of existential types=20
too.</FONT></FONT></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0049_01C2D2D8.641D5CD0--