updating labelled fields

Hal Daume III hdaume@ISI.EDU
Mon, 6 May 2002 09:51:28 -0700 (PDT)


Hi,

I often create structures like:

data MyData = MyData { foo :: ..., bar :: ..., .... }

and most of the time i do one of two things:

  1) read values from the structure, as in:
             let x = (foo myData) in ... 
  2) update values in the structure, as in:
             let myData' = myData { foo = (foo myData)+1 }

Only very rarely (usually only during intializization) do I actually put
values into the structure that *don't* depend on their previous value.  I
end up with expresions like:

... myData { foo = (foo myData) + 1 ;
             bar = (bar myData) ++ "bar" ;
             ick = (ick myData) ! n ; ... }

I was wondering if there existed any sort of "update" syntax.  Obviously
not real update, but enough to get rid of the "(foo myData)" parts of my
epxression which really serve to just clutter up with expression.  Perhaps
something like:

... myData { foo <- (+1) ; bar <- (++"bar") ; ick <- (!n) ; ... }

or the like, where "x { ... y <- e ... } is translated to "x { ... y = e
(y x) ... }"  (i only use "<-" because that seems to be the default
extension symbol, i guess because we don't want to trample symbols people
might actually use.)

Anyway, does such a thing exist, and, if not, is there any chance it could
exist, or is it just syntactic salt to too many people? :)

 - Hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume