[Template-haskell] Re: [Haskell] Proposal: Allow "\=" for field
update in record update syntax
Simon Peyton-Jones
simonpj at microsoft.com
Tue Mar 8 04:03:20 EST 2005
To have what you want takes a syntactic extension to Haskell; TH
requires '$' to indicate splices. You'd have to write something like
$( [| name |] =:= val )
instead of
name := val
where (=:=) :: ExpQ -> a -> ExpQ
You can do that today, but I guess you won't find it as convenient.
It's very hard to know where to stop when adding syntax; and the record
design space is particularly complicated (there have been many
proposals, all with different relative merits). And defining new
syntax often makes some existing programs stop working; in this case,
ones that use ":=" as a data constructor.
Simon
| -----Original Message-----
| From: S. Alexander Jacobson [mailto:alex at alexjacobson.com]
| Sent: 07 March 2005 16:46
| To: Simon Peyton-Jones
| Cc: template-haskell at haskell.org; Sander Evers
| Subject: RE: [Template-haskell] Re: [Haskell] Proposal: Allow "\=" for
field update in record update
| syntax
|
| Most generally, I use records all over the place in my code (is this
| bad style?), and the current syntax for record update is really
| unwieldy.
|
| I'd like some way to have operators like (:=) and (:\=) for record
| update. I don't yet know TemplateHaskell so I don't know how you
| define functions in it, but I would like some way to write:
|
| name := val = \rec-> rec { name = val}
| name :\= fn = \rec -> rec { name = fn $ name rec}
|
| And I would like to be able to use these operators as Sander Evers
| showed:
|
| data Country = Country {capital :: City, ...}
| data City = City {inhabitants :: Int, ...}
|
| birth_in_capital :: Country -> Country
| birth_in_capital = capital :\= (inhabitants :\= (+1))
|
| It would be even nicer if we could define the precedence of these
| operators so that we could write the above
|
| birth_in_capital = capital :\= inhabitants :\= (+1)
|
| Though since haskell is usually prefix, perhaps it would be best to be
| able to write it:
|
| birth_in_capital = (+1) :\= inhabitants :\= capital
|
| Note: It is entirely possible that this is a Haskell rather than a
| template haskell issue. I don't know the border between the projects.
|
| -Alex-
|
| ______________________________________________________________
| S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
|
|
|
| On Mon, 7 Mar 2005, Simon Peyton-Jones wrote:
|
| > What exactly is it that TH doesn't support, that you want?
| >
| > Simon
| >
| > | -----Original Message-----
| > | From: template-haskell-bounces at haskell.org
| > [mailto:template-haskell-bounces at haskell.org] On
| > | Behalf Of S. Alexander Jacobson
| > | Sent: 28 February 2005 10:32
| > | To: Sander Evers; template-haskell at haskell.org
| > | Subject: [Template-haskell] Re: [Haskell] Proposal: Allow "\=" for
| > field update in record update syntax
| > |
| > | Since operators can't start with a ':', is there an in-principle
| > | reason TH does not support : operators? The syntax below would be
| > | really nice to have.
| > |
| > |
| > |
| > | On Fri, 18 Feb 2005, Sander Evers wrote:
| > |
| > | >
| > | >> Then we could have e.g. (:=) and (:\=) and end up with a
| > | >> syntax that looks like this:
| > | >>
| > | >> rec // field :\= fn . field2 := val
| > | >>
| > | >> And that is BETTER than the Haskell syntax that I originally
| > proposed.
| > | >
| > | > This syntax is also nice for composition of update functions,
which
| > is useful
| > | > with nested records:
| > | >
| > | > data Country = Country {capital :: City, ...}
| > | > data City = City {inhabitants :: Int, ...}
| > | >
| > | > birth_in_capital :: Country -> Country
| > | > birth_in_capital = capital :\= (inhabitants :\= (+1))
| > | >
| > | > This also shows that it would be useful to make :\= associate to
the
| > right.
| > | >
| > |
| > | ______________________________________________________________
| > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
| > | _______________________________________________
| > | template-haskell mailing list
| > | template-haskell at haskell.org
| > | http://www.haskell.org/mailman/listinfo/template-haskell
| >
More information about the template-haskell
mailing list