[racket] keyword arguments for type constructors?

From: Alexander D. Knauth (alexander at knauth.org)
Date: Sat Jun 7 07:24:03 EDT 2014

That’s helpful, but I’m fine with defining my version of name/kw myself (and I have more control over it anyway).  

What I’m really trying to do is define a type for typed/racket.  Sorry I wasn’t very clear about that.  

On Jun 7, 2014, at 4:57 AM, Manfred Lotz <manfred.lotz at arcor.de> wrote:

> 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))
>> 
>> 
>> 
> 
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.