Browse thread
[Caml-list] suggestion for record pattern matching and construction
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | brogoff@s... |
| Subject: | Re: [Caml-list] suggestion for record pattern matching and construction |
On Thu, 11 Sep 2003, Olivier Andrieu wrote:
> Eric C. Cooper [Wednesday 10 September 2003] :
> >
> > I find that I am often writing code like
> > { field1 = field1; field2 = field2; field3 = field3 }
> > when matching and constructing records. I guess it's because thinking
> > up good names for the record fields is nontrivial and having similar
> > but different names for the bindings just bothers me.
> >
> > How about allowing syntax like that used for labels:
> > { ~field1; ~field2; ~field3 }
> > would expand into the above, in both pattern matching and construction
> > contexts.
>
> I have a camlp4 extension that does exactly this (well, without
> the ~). Also, you can put the module path before the { instead of
> having to repeat it for each field. So :
>
> Mod1.Mod2.{ field1; field2 }
>
> is expanded into
>
> { Mod1.Mod2.field1 = field1 ; Mod1.Mod2.field2 = field2 }
I like it, though I can even see an argument for the ~ syntax Eric suggests as
it dovetails nicely with labels. I especially like your sugar which reduces
the number of module qualifications.
Is there any chance we could see a feature like this in the core language
syntax? Especially since 3.07, I am more inclined to use "private" record
types a lot more, and since I'd also like to minimize my use of open, this
lighter syntax makes it even more appealing.
-- Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners