【问题标题】:Access type information in macro in typed/racket在 typed/racket 中访问宏中的类型信息
【发布时间】:2015-06-28 20:18:52
【问题描述】:

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

(需要(用于语法球拍/结构信息 语法/解析)) (定义语法(显示结构信息 stx) (语法解析 stx [(显示结构信息名称:id) (display (extract-struct-info (syntax-local-value #'name))) #'(列表)])) (结构:s([a:数字] [b:字符串])) (显示结构信息)

输出:

(.#<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) 中的类型列表,或者查看 polymorphic type 的参数?

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

相关:Get the type information in macros(Common Lisp 的相同问题)

【问题讨论】:

    标签: reflection racket typed-racket


    【解决方案1】:

    来自良好的权威(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
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2017-04-01
        • 2021-07-11
        • 1970-01-01
        • 2015-06-08
        • 2012-10-14
        • 2014-05-27
        • 1970-01-01
        • 1970-01-01
        • 2012-03-22
        相关资源
        最近更新 更多