[Haskell] Improvements to GHC

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Nov 17 17:44:49 EST 2005

On Thu, 2005-11-17 at 22:11 +0000, Claus Reinke wrote:
> > > To solve this problem I just made them all instances of a class with a
> > > gameId function.  Still, not ideal.
> > 
> > That gives you a getter function but you would then need an extra setter
> > function.
> But there is no need to have two names for each label when you 
> only want to talk about two ways of using any given label (untested
> code here, but I've used something similar in practice, and similar
> patterns are in use in various libraries, I think):
> -- what we expect from record field labels
> data Label t r = Label { get :: r -> t, put :: t -> r -> r }

Indeed we use this "named label/attribute is a pair of getter and
setter" idea in Gtk2Hs (which we borrowed from wxHaskell which in turn
borrowed it from Yampa).

This is for monadic attributes rather than pure record labels. We end up
with a syntax like so:

set button [ label := "blah", borderWidth := 10 ]
something <- get label

These can be made instances of classes so that different objects can
have the same attribute names (wxHaskell does this).


More information about the Haskell mailing list