Will this help: #lang typed/racket
(define-syntax (the stx) (syntax-case stx () [(_ (define (f x) e)) (let ((capital-x (capitalize stx #'x))) #`(begin (: f (-> #,capital-x #,capital-x)) (define (f x) e)))])) (define-for-syntax (capitalize stx x) (define x:str (symbol->string (syntax-e x))) (datum->syntax stx (string->symbol (string-titlecase x:str)))) (define-type X Integer) (the (define (f x) x)) (f 10) (f 'a) ;; <-- type check fails, comment out On Oct 7, 2014, at 2:38 PM, Jack Firth <jackhfi...@gmail.com> wrote: > I read a tweet about someone wistfully wishing there was some sort of "the" > operator in a typed non-parensy language such that one could write something > like this: > > Customer someFunc(the customer) { ... } > > and have it mean: > > Customer someFunc(Customer customer) { ... } > > Basically, an operator to take care of the common case where the variable > name is just the lower-camel-case form of the type. As a Racket fan, I wanted > to see if I could do this with a macro in Typed Racket. After some mucking > around I had a form that handled the syntax correctly, but I couldn't use it > in typed racket because the type checker and type annotations run as macros > *before* my macro expands. As I read further, it seems to be the case that > macros in typed racket are a very thorny problem and an area of open > research. So is it currently possible to implement a "the" operator like the > one shown above in typed racket? And if so, how would it be done? > ____________________ > Racket Users list: > http://lists.racket-lang.org/users ____________________ Racket Users list: http://lists.racket-lang.org/users