I think I've asked a question like this in the past, but I still haven't
found a good solution. I'm going to give a concrete example:

Let's say I have a `date` struct like this:

(struct date (y m d))


And I'm perfectly happy with the default match expander:

(match d
  [(date y m d) ...])


But I want a custom constructor:

(define (date* y [m 1] [d 1])
  (date y m d))


And, of course, I want to provide the custom constructor as `date`, not
`date*`:

(define make-date
  (procedure-rename
   (λ (y [m 1] [d 1])
     (date y m d))
   'date))

(define-match-expander $date
  (syntax-rules ()
    [(_ y m d) (date y m d)])
  (λ (stx)
    (syntax-case stx ()
      [(_ xs ...) #'(make-date xs ...)]
      [_ #'make-date])))

(provide (rename-out [$date date]))


But I also want to provide the constructor with a contract:

(provide/contract
  [rename
    $date date
     (->i ([year exact-integer?])
           ([month (integer-in 1 12)]
            [day (year month) (day-of-month/c year month)])
            [d date?])])


Unfortunately, although this provides `date` as a constructor function, it
does not allow it to be used as a match expander.

What's the best way of getting both?

I think it might work if I defined `make-date` above with `define/contract`
(thus narrowing the contract boundary) and then doing the normal `(provide
(rename-out ...))`, as in the second-to-last example, above.

But is there a painless way to accomplish this without narrowing the
contract boundary?

-Jon

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to