[racket] keyword arguments for type constructors?
Hi Alexander,
I asked this question some time ago:
http://article.gmane.org/gmane.comp.lang.racket.user/3420/match=structure+question
I got a very good answer from Matthias Felleisen who showed how this
could be achieved:
http://article.gmane.org/gmane.comp.lang.racket.user/3437/match=structure+question
Hope this helps in some way.
--
Manfred
On Fri, 6 Jun 2014 16:59:41 -0400
"Alexander D. Knauth"
<alexander at knauth.org> wrote:
> 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))
>
>
>