[racket] Determining type from a syntax object

From: Antonio Menezes Leitao (antonio.menezes.leitao at ist.utl.pt)
Date: Mon Jun 23 05:23:54 EDT 2014

Hi,

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.

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:

;;;;;;;;;;;File test-macros.rkt
#lang typed/racket

(begin-for-syntax
  (require syntax/id-table)
  (define table (make-free-id-table))
   (define (set-id-info! id info)
    (free-id-table-set! table id info))
  (define (get-id-info id)
    (free-id-table-ref table id))
  (provide get-id-info))

(define-syntax (define-saving-types stx)
  (syntax-case stx ()
    [(def (name [p t] ...) body ...)
     (syntax/loc stx
       (begin
         (begin-for-syntax
            (set-id-info! #'name #'([p t] ...)))
         (define (name [p : t] ...) body ...)))]))

(define-syntax (define-list-version stx)
  (syntax-case stx ()
    [(def name from)
     (with-syntax ([([p t] ...) (get-id-info #'from)])
       (syntax/loc stx
         (define (name [p : t] ...)
           (list p ...))))]))

(provide define-saving-types define-list-version)
;;;;;;;;;;;

Now, in a different file, I have:

;;;;;;;;;;;File foo.rkt
#lang typed/racket
(require "test-macros.rkt")

(define-saving-types (foo [x Real] [y Float]) (+ x y))
(provide foo)

(define-list-version bar foo)
;;;;;;;;;;;

In the previous situation, everything works as expected: bar is defined
using the same parameter types as foo.

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.

;;;;;;;;;;;File baz.rkt
#lang typed/racket

(require "test-macros.rkt")
(require "foo.rkt")

(define-list-version baz foo)
;;;;;;;;;;;

Oddly, everything works as (I) expected if I move all the stuff to untyped
racked (adjusting for the untyped definition syntax).

What I'm I doing wrong?

Best,
António.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140623/cff874b0/attachment-0001.html>

Posted on the users mailing list.