<div dir="ltr">Hi,<div><br></div><div>I was trying to achieve something similar but found a problem in my code. I'll be glad if someone can help me solve this.</div><div><br></div><div>The idea is that I want to define a typed function and then I want to access the parameter types to define a different function. The file containing the macro stuff is:</div>
<div><br></div><div>;;;;;;;;;;;File test-macros.rkt</div><div><div>#lang typed/racket</div><div><br></div><div>(begin-for-syntax</div><div> (require syntax/id-table)</div><div> (define table (make-free-id-table))</div>
<div>
(define (set-id-info! id info)</div><div> (free-id-table-set! table id info))</div><div> (define (get-id-info id)</div><div> (free-id-table-ref table id))</div><div> (provide get-id-info))</div><div><br></div><div>
(define-syntax (define-saving-types stx)</div><div> (syntax-case stx ()</div><div> [(def (name [p t] ...) body ...)</div><div> (syntax/loc stx</div><div> (begin</div><div> (begin-for-syntax</div>
<div>
(set-id-info! #'name #'([p t] ...)))</div><div> (define (name [p : t] ...) body ...)))]))</div><div><br></div><div>(define-syntax (define-list-version stx)</div><div> (syntax-case stx ()</div>
<div> [(def name from)</div><div> (with-syntax ([([p t] ...) (get-id-info #'from)])</div><div> (syntax/loc stx</div><div> (define (name [p : t] ...)</div><div> (list p ...))))]))</div><div>
<br></div><div>(provide define-saving-types define-list-version)</div></div><div>;;;;;;;;;;;<br></div><div><br></div><div>Now, in a different file, I have:</div><div><br></div><div>;;;;;;;;;;;File foo.rkt<br></div><div><div>
#lang typed/racket</div><div>(require "test-macros.rkt")<br></div><div><br></div><div>(define-saving-types (foo [x Real] [y Float]) (+ x y))</div><div>(provide foo)</div><div><br></div><div>(define-list-version bar foo)</div>
</div><div><div>;;;;;;;;;;;<br></div></div><div><br></div><div>In the previous situation, everything works as expected: bar is defined using the same parameter types as foo.</div><div><br></div><div>Unfortunately, if I decide to do a similar thing in a different file baz.rkt, I get an error, saying that there is no mapping for foo.</div>
<div><br></div><div>;;;;;;;;;;;File baz.rkt<br></div><div><div>#lang typed/racket</div><div><br></div><div>(require "test-macros.rkt")</div><div>(require "foo.rkt")</div><div><br></div><div>(define-list-version baz foo)</div>
</div><div>;;;;;;;;;;;</div><div><br></div><div>Oddly, everything works as (I) expected if I move all the stuff to untyped racked (adjusting for the untyped definition syntax).</div><div><br></div><div>What I'm I doing wrong?</div>
<div><br></div><div>Best,</div><div>António.</div></div>