updating labelled fields

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


I just fudgeted around in the ghc source code and this doesn't seem to be
a change that would require a lot of work.  Briefly, the changes that
would need to be made would be:

  1) In the parser, change bind so that in addition to 
            qname '=' exp
     you can also have
            qname 'somefunkysymbol' exp
     And change the return type from (a,b,Bool) to (a,b, Either
     () Bool) and then for the normal case, returh Right False and for the
     update case return Left ().

  2) in the mkRecConstrOrUpdate function, when you have a conid
     applied to an update, make sure there are no Left () guys
     in the list; otoh, if the guy sitting in from of the { is
     an exp, do a map (mkRecUpdate exp) on the list where this
     function is something like:

  mkRecUpdate exp (a,b,Right c) = (a,b,c)
  mkRecUpdate exp (a,b,Left ()) = (a,HsApp b (HsApp (HsVar a) exp),False)
  -- warning, this isn't 100% correct, but it's the basic idea

  3) recompile ghc

I wouldn't at all mind making this addition if I had a sense that it would
actually be accepted and that people weren't going to go crazy over the
syntax.  Would something like "<-" be preferred or something like "$=>"?

 - Hal

--
Hal Daume III

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

On Tue, 7 May 2002, Bryn Humberstone wrote:

> Hi Hal,
> 
> >   2) update values in the structure, as in:
> >              let myData' = myData { foo = (foo myData)+1 }
>   
> I do this a lot too, and think it would be lovely to have some sugar for
> it. My original idea for the syntax was something like 
> myData = myData { foo $=> (+1),
>                   bar $=> (*2) }
> just because $ is a bit reminiscent of function application. But I'm not
> really fussed; as long as some syntax for it appeared in the language.
> 
> -- Bryn
> 
> -- 
> Bryn Humberstone
>   + Email bdh@alphalink.com.au         
>   + Web   http://bryn.alphalink.com.au/
>