[racket] keyword arguments for type constructors?
Is there a way to define a type constructor that accepts keyword arguments?
I know that things like the Class type constructor do this already, so is there a way to define something like this myself?
The reason is I have a struct that represents a dimension (as in dimensional analysis and units) and I want a type constructor that lets me make types for specific instances of it without having to remember what order the fields go in:
(struct: (Length-Expt Mass-Expt Time-Expt Charge-Expt Temp-Expt)
dimension
([length-expt : Length-Expt]
[mass-expt : Mass-Expt]
[time-expt : Time-Expt]
[charge-expt : Charge-Expt]
[temperature-expt : Temp-Expt])
)
(define (dimension--kws #:length^ [length-expt 0]
#:mass^ [mass-expt 0]
#:time^ [time-expt 0]
#:charge^ [charge-expt 0]
#:temperature^ [temp-expt 0])
(dimension length-expt mass-expt time-expt charge-expt temp-expt))
;; I want to be able to do something that would do the same thing as this: (it doesn't have to be this easy)
(define-type (Dimmension--kws #:length^ Length-Expt
#:mass^ Mass-Expt
#:time^ Time-Expt
#:charge^ Charge-Expt
#:temperature^ Temp-Expt)
(dimension Length-Expt Mass-Expt Time-Expt Charge-Expt Temp-Expt))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140606/5b694a1a/attachment-0001.html>