[plt-dev] some Racket proposals & implementation

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Tue Apr 6 12:37:34 EDT 2010

On Sat, Apr 3, 2010 at 7:58 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>
>> Another possibility is that `match' could treat identifiers bound to
>> static struct info as pattern constructors, even without them being
>> match expanders.  This would probably be really easy to implement.
>
> I think that's a good idea. (It's what I had in mind originally.)

This is indeed very easy to implement.  But it doesn't do everything
that Jay's match expander does.  In particular, his match expander
handles keywords to specify field patterns, like this:

(define-struct a (#:b b))

(match (make-a #:b 1)
  [(a #:b x) (add1 x)])

This is very nice, but I think a match expander is the wrong way to get it.

1. That requires bringing in all of match into the implementation of
`define-struct', which has performance problems.
2. It might be nice to support keywords for *all* structs, not just
those defined with keywords, like this:

(define-struct a (b))

(match (make-a  1)
  [(a #:b x) (add1 x)])

However, this seems like it requires `match' knowing the field names
statically.  Right now, static struct info has the accessor names, but
not the field names.  I think unhygenically ripping off the part
before the `-' is terrible (and probably impossible to do correctly).
But what's the best way to extend the static struct info API?
-- 
sam th
samth at ccs.neu.edu


Posted on the dev mailing list.