F#中未键入/键入的代码引号与宏卫生之间是否存在关系? [英] Is there a relationship between untyped/typed code quotations in F# and macro hygiene?

查看:83
本文介绍了F#中未键入/键入的代码引号与宏卫生之间是否存在关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道F#中未键入/键入的代码引号与宏系统的卫生状况之间是否存在关系.他们是用各自的语言解决相同的问题,还是他们分开解决问题?

I wonder if there is a relationship between untyped/typed code quotations in F# and the hygiene of macro systems. Do they solve the same issues in their respective languages or are they separate concerns?

推荐答案

引号是元编程的一种形式.它们使您可以以编程方式操作抽象语法树,然后可以将其抽象为代码并进行评估.

Quotations are a form of meta-programming. They allow you to manipulate abstract syntax trees programmatically, which can be in turned spliced into code, and evaluated.

类型引号会将AST的类型化后缀嵌入宿主语言的类型系统中,因此它们可确保您不会生成错误类型的代码片段.无类型的报价不提供保证(它可能因运行时错误而失败).

Typed quotations embed the reified type of the AST in the host language's type system, so they ensure you cannot generate ill-typed fragments of code. Untyped quotations do not offer that guarantee (it may fail with a runtime error).

顺便说一句,键入的引号与Template Haskell准引号非常相似.

As an aside, typed quotations are strongly similar to Template Haskell quasiquotations.

类Lisp语言中的Hygenic宏是相关的,因为它们存在以支持元编程.但是,出于卫生考虑,是为了避免简单的名称捕获混乱,已经避免了(甚至更多)键入准引号的事情.

Hygenic macros in Lisp-like languages are related, in that they exist to support meta-programming. The hygiene however is for simple name capture confusion, something that typed quasi quotations already avoid (and more).

是的,它们是相似的,因为它们分别是用于类型化和非类型化语言的元编程的机制.键入的准引号和Hygenic宏都为完全未键入的,不健全的元编程增加了额外的安全性.他们为程序员提供的保证水平虽然有所不同.输入的引号严格更强.

So yes, they are similar, in that they are mechanisms for meta-programming in typed and untyped languages, respectively. Both typed quasi quotes and hygenic macros add additional safety to fully untyped, unsound meta programming. The level of guarantee they offer the programmer though is different. The typed quotes are strictly stronger.

这篇关于F#中未键入/键入的代码引号与宏卫生之间是否存在关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆