Proposal: FirstClassFieldUpdates

Henrik Nilsson nhn at Cs.Nott.AC.UK
Tue Jul 28 09:16:00 EDT 2009

Hi all,

Jon Fairbairn <jon.fairbairn at> wrote:

 > Isaac Dupree <ml at> wrote:
 > >
 > > yes it is, however field updates are occasionally slightly
 > > annoying, since they can't change something's type at all,
 > > IIRC.  Say,
 > > data C nx ny = C { x :: nx, y :: ny }
 > > x_set :: nx2 -> C nx1 ny -> C nx2 ny
 > > --x_set x2 c = c {x = x2}  --type error
 > If that were the case, it would be a serious wart that needed to be
 > addressed. However, implementation would be fairly straightforward as
 > an "extension" is already present in ghc:
 >    let x_set x2 c = c{x=x2}
 >    :t x_set
 >    x_set :: nx -> C t ny -> C nx ny
 > ;-)  (or did I misunderstand you?)

Indeed, field update can change the type, which I guess is the point
Jon is making. And Isaac's example above compiles without any problems
or extensions. H98 as far as I'm aware.

However, there are cases where the current field update facility
arguably isn't good enough, namely when there are more than one
constructor, some of which do not have certain of the fields. See

for examples, in particular "Polymorphic Record Update take II".

As an aside, having revisited that discussion, I still think the idea of
being able to do an update for constructors that do NOT have
certain fields makes a lot of sense. The record wildcard extension,
that was mentioned as a possible workaround, seems far less appealing
and flexible. I don't even know what it would mean if it's used more
than once in a scope, e.g. what about the following:

     f (C1 {a = 1, ..}) (C2 {b = 2, ..}) =
         (C1 {a = 10, ..}, C2 {b = 20, ..})




Henrik Nilsson

School of Computer Science
The University of Nottingham
nhn at

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

More information about the Haskell-prime mailing list