[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> </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. (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.) You might prefer to choose a different symbol, =
such as=20
(:=3D=3D) or (::=3D). </DIV>
<DIV> </DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>Thanks for mentioning this. =
However, (:=3D)=20
is a 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> </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 -- lazy =
binding<BR>let! -- strict binding<BR>let$ =
-- speculative binding (ie. try operationally strictly but =
maintain lazy semantics)<BR>let# -- monomorphic binding =
?</PRE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>...</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>-- Daan.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr>Dean <BR> </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>> 2. The :=3D=20
operator.</FONT></FONT> <BR><FONT face=3DArial><FONT =
size=3D-1>> The =3D:=20
function should say "assign to this property". Is seems to be=20
the</FONT></FONT> <BR><FONT face=3DArial><FONT size=3D-1>> 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>> 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 :-) (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 =3D Attr (w -> IO =
a) (w -> a -> IO ()) -- getter and setter</PRE><PRE>data =
Prop w =3D forall a. (:=3D) (Attr w a) =
a -- :=3D is a =
constructor</PRE><PRE>set :: w -> [Prop w] -> IO ()
set w props
=3D mapM_ setProp props
where
setProp ((Attr getter setter) :=3D x)
=3D setter w x</PRE><PRE>get :: w -> =
Attr w a -> IO a
get w (Attr getter setter)
=3D getter w</PRE><PRE>-- 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)</PRE><PRE>...</PRE><PRE>gui =3D do ...
set frame [title :=3D =
"hi there"]</PRE> =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--