[GUI] get and set
Daan Leijen
daanleijen@xs4all.nl
Sun, 16 Feb 2003 17:10:40 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_005C_01C2D5DE.54BF89D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
> After a look at Yahu/GIO I decided to use set/get/=3D: in 'HOpenGL: =
The
Good plan. Since wxWindows has an openGL canvas widget, we may
want to work more closely on this in the future :-)
> My question is: The attribute/property/state variable pattern seems to
> be a more universal concept than I initially thought, so it might be a
> good idea to have support for this in the standard libraries. But
> exactly how is not completely clear to me, e.g. GIO uses an additional
> type variable (for the kind of widget). Any ideas and/or suggestions?
It certainly seems more generally applicable than just gui's. However,
I would suggest a small change to your approach where you define a =
getter
and setter class. Instead, I would focus on "attributes". That is, =
"get" and
"set" work universally on attributes. Suppose for now that we don't use
a write/read only distinction. An attribute has both a type "a" and a =
thing that
it belongs to "w". I wonder why the "thing it belongs to" is absent from =
your
approach as it seems quite fundamental to me. It allows you for example =
to organise
the attributes in type classes and re-use the same attribute name for =
different
kind of things.
data Attr w a =3D Attr{ getter :: w -> IO a, setter :: a -> w -> IO () =
}get :: Attr w a -> w -> IO aget attr w =3D (getter attr) wFor, =
setting, we use properties -- attributes that are already associated =
with a value. This allows us
to both a bunch of them in lists.
data Prop w =3D forall a. Prop (Attr w a) a -- or even: forall a. =
(Attr w a) :=3D a(=3D:) :: Attr w a -> a -> Prop wattr =3D: x =3D Prop =
attr xOr, if you stick to Haskell98:
data Prop w =3D Prop (w -> IO ())(=3D:) :: Attr w a -> a -> Prop wattr =
=3D: x =3D Prop ((setter attr) x)And set works like:
set :: [Prop w] -> w -> IO ()set props w =3D mapM_ (\(Prop setter) -> =
setter w) propsNow, regarding openGL with state variables, you would =
make
attributes that work on those, for example:
value :: Attr (IORef a) avalue =3D Attr (getIORef) (setIORef)So, even =
openGL will assign attributes to certain kind of things.
Furthermore, you can still make a read/write distinction by putting
"get" and ":=3D" in classes as you do:
class Readable attr where get :: attr w a -> w -> IO aclass Writable =
attr where (=3D:) :: attr w a -> a -> Prop winstance Readable Attr =
where ...instance Writable Attr where ...But I am personally a bit =
hesitant to do this as it might give rise
to rather complex error messages -- but only experience will show
whether this is actually the case.=20
> OK, modules like this look rather obvious and small, so why should we
> standardize it at all? Linguistic abstraction! Having a set of =
standard
> functions/operators available for a common task is always a good idea,
> it makes other people's programs (and old ones written by oneself :-)
I totally agree. I hope though that we can find a really general =
abstraction
that will also work for the GUI's or otherwise it doesn't make much =
sense.
Therefore, i am quite curious if the approach that is focused on =
"Attributes"
as sketched in this mail will also work for openGL.
All the best,
Daan.
> much easier to read. Embedding a domain specific language into Haskell
> by defining myriads of home-grown operators is often a fine way of
> obfuscating a program (Prolog programs are often not much better in =
this
> respect, BTW).
>=20
> > If :=3D is going to be a reserved symbol one day, then we should =
perhaps
> > not use it. [...]
>=20
> I wasn't aware of that, but it's just another reason...
>=20
> Cheers,
> S.
>=20
> _______________________________________________
> GUI mailing list
> GUI@haskell.org
> http://www.haskell.org/mailman/listinfo/gui
>=20
>
------=_NextPart_000_005C_01C2D5DE.54BF89D0
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.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>> After a look at Yahu/GIO I decided =
to use=20
set/get/=3D: in 'HOpenGL: The</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Good plan. Since wxWindows has an =
openGL canvas=20
widget, we may</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>want to work more closely on this in =
the future=20
:-)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><BR><FONT face=3DArial =
size=3D2>> My question=20
is: The attribute/property/state variable pattern seems to<BR>> be a =
more=20
universal concept than I initially thought, so it might be a<BR>> =
good idea=20
to have support for this in the standard libraries. But<BR>> exactly =
how is=20
not completely clear to me, e.g. GIO uses an additional<BR>> type =
variable=20
(for the kind of widget). Any ideas and/or suggestions?<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It certainly seems more generally =
applicable than=20
just gui's. However,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I would suggest a small change to your =
approach=20
where you define a getter</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>and setter class. Instead, I =
would focus on=20
"attributes". That is, "get" and</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>"set" work universally on attributes. =
Suppose for=20
now that we don't use</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>a write/read only distinction. An =
attribute has=20
both a type "a" and a thing that</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>it belongs to "w". I wonder why the =
"thing it=20
belongs to" is absent from your</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>approach as it seems quite fundamental =
to me. It=20
allows you for example to organise</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>the attributes in type classes and =
re-use the same=20
attribute name for different</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>kind of =
things.</FONT></DIV><PRE>data Attr w a =3D Attr{ getter =
:: w -> IO a, setter :: a -> w -> IO () }</PRE><PRE>get :: Attr =
w a -> w -> IO a<BR>get attr w =3D (getter attr) w</PRE>
<DIV><FONT face=3DArial size=3D2>For, setting, we use properties -- =
attributes that=20
are already associated with a value. This allows us</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>to both a bunch of them in =
lists.</FONT></DIV><PRE>data Prop w =3D forall a. Prop (Attr w a) a -- =
or even: forall a. (Attr w a) :=3D a</PRE><PRE>(=3D:) :: Attr w a -> =
a -> Prop w<BR>attr =3D: x =3D Prop attr x</PRE>
<DIV><FONT face=3DArial size=3D2>Or, if you stick to =
Haskell98:</FONT></DIV><PRE>data Prop w =3D Prop (w -> IO =
())</PRE><PRE>(=3D:) :: Attr w a -> a -> Prop w<BR>attr =3D: x =
=3D Prop ((setter attr) x)</PRE>
<DIV><FONT face=3DArial size=3D2>And set works =
like:</FONT></DIV><PRE>set :: [Prop w] -> w -> IO ()<BR>set props =
w<BR> =3D mapM_ (\(Prop setter) -> setter w) props</PRE><FONT=20
face=3DArial size=3D2>
<DIV>Now, regarding openGL with state variables, you would make</DIV>
<DIV>attributes that work on those, for =
example:</DIV></FONT><PRE>value :: Attr (IORef a) =
a<BR>value =3D Attr (getIORef) (setIORef)</PRE><FONT=20
face=3DArial size=3D2>
<DIV>So, even openGL will assign attributes to certain kind of =
things.</DIV>
<DIV>Furthermore, you can still make a read/write distinction by =
putting</DIV>
<DIV>"get" and ":=3D" in classes as you do:</DIV></FONT><PRE>class =
Readable attr where<BR> get :: attr w a -> w -> IO =
a</PRE><PRE>class Writable attr where<BR> (=3D:) :: attr w a -> a =
-> Prop w</PRE><PRE>instance Readable Attr where ...<BR>instance =
Writable Attr where ...</PRE>
<DIV><FONT face=3DArial size=3D2>But I am personally a bit hesitant to =
do this as it=20
might give rise</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>to rather complex error messages -- but =
only=20
experience will show<BR>whether this is actually the case. =
</FONT></DIV><FONT=20
face=3DArial size=3D2>
<DIV><BR></FONT><FONT face=3DArial size=3D2>> OK, modules like this =
look rather=20
obvious and small, so why should we<BR>> standardize it at all? =
Linguistic=20
abstraction! Having a set of standard<BR>> functions/operators =
available for=20
a common task is always a good idea,<BR>> it makes other people's =
programs=20
(and old ones written by oneself :-)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I totally agree. I hope though that we =
can find a=20
really general abstraction</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>that will also work for the GUI's or =
otherwise it=20
doesn't make much sense.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Therefore, i am quite curious if the =
approach that=20
is focused on "Attributes"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>as sketched in this mail will =
</FONT><FONT=20
face=3DArial size=3D2>also work for openGL.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>All the best,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> Daan.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> </DIV>
<DIV><BR>> much easier to read. Embedding a domain specific language =
into=20
Haskell<BR>> by defining myriads of home-grown operators is often a =
fine way=20
of<BR>> obfuscating a program (Prolog programs are often not much =
better in=20
this<BR>> respect, BTW).<BR>> <BR>> > If :=3D is going =
to be a=20
reserved symbol one day, then we should perhaps<BR>> > not =
use it.=20
[...]<BR>> <BR>> I wasn't aware of that, but it's just another=20
reason...<BR>> <BR>> Cheers,<BR>> S.<BR>> =
<BR>> _______________________________________________<BR>> GUI =
mailing=20
list<BR>> </FONT><A href=3D"mailto:GUI@haskell.org"><FONT =
face=3DArial=20
size=3D2>GUI@haskell.org</FONT></A><BR><FONT face=3DArial size=3D2>> =
</FONT><A=20
href=3D"http://www.haskell.org/mailman/listinfo/gui"><FONT face=3DArial=20
size=3D2>http://www.haskell.org/mailman/listinfo/gui</FONT></A><BR><FONT =
face=3DArial size=3D2>> <BR>> </FONT></DIV></BODY></HTML>
------=_NextPart_000_005C_01C2D5DE.54BF89D0--