在 typed/racket 中访问宏中的类型信息

Access type information in macro in typed/racket

如何使用 typed/racket 语言访问结构成员的类型?函数 extract-struct-info 确实给出了字段访问器的列表,但没有给出它们的类型。

(require (for-syntax racket/struct-info
                     syntax/parse))

(define-syntax (display-struct-info stx)
  (syntax-parse stx
    [(display-struct-info name:id)
     (display (extract-struct-info (syntax-local-value #'name)))
     #'(list)]))

(struct: s ([a : Number] [b : String]))

(display-struct-info s)

输出:

(.#<syntax:12:9 struct:s> .#<syntax make-s> .#<syntax:12:9 s?> (.#<syntax:12:9 s-b> .#<syntax:12:9 s-a>) (#f #f) #t)'()

更一般地说,如何访问 typed/racket 的类型,例如获取 union type (U Number String 'foo 'bar), or seeing the arguments to a polymorphic type 中的类型列表?

我只对宏扩展时间访问感兴趣, 运行时间访问。

相关:(Common Lisp 的相同问题)

来自权威人士(Typed Racket 的开发者)[来自 freenode 上的#racket irc 频道]:

mithos28: ... the brief answer is that types are not available until after macro expansion
soegaard: Quoting: "I am interested only in macro-expansion-time access, not run-time access."
soegaard: So only after - or also during?
mithos28: only after. #%module-begin from TR does an local expand of the body and then once that returns traverses it and checks types and generates contracts/optimizes

现在可能有一个新的答案,但是使用 Typed/Racket 的替代方法:turnstile Racket 库允许创建类型化语言,在其中可以在编译时访问与表达式关联的类型.

遗憾的是,我对turnstile了解不够(还?)无法提供详细示例。