Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] Record pattern matching
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] Record pattern matching
> >       You'd rather be forced to code something like:
> >
> >       function { a=a; b=_ } -> a;;
> >
> > where all the fields have to be named, but some of them can
> > be specified as ignored?

No, but as Don suggested having alternative syntax would be preferable.
SML for example distinguishes the patterns

	{a = p}

and

	{a = p, ...}

> I guess the point is that I don't use record pattern matching much, and
> where I do I don't want partial matches.  Or at least I have a cases
> where enforcing full matching would catch more bugs.

This has been my experience as well when modifying record types.

> > There is a sense in which
> >
> >       record.a
> >
> > is just a shorthand for
> >
> >       match record with { a=value } -> value
> >
> > which means that you might argue that the notation
> >
> >       record.a
> >
> > should be completed by naming every field too :-)

In SML the record selection function #a in fact is sugar for

	fn {a=x, ...} => x

Best regards,

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids.
 If Pac Man affected us as kids, we would all be running around in
 darkened rooms, munching pills, and listening to repetitive music."
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr