F#类型提供程序与Lisp宏 [英] F# Type Providers vs. Lisp macros

查看:100
本文介绍了F#类型提供程序与Lisp宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关F#3.0类型提供程序的信息(例如,此处),似乎它们是基于一种编译时代码生成的.在这方面,我想知道它们如何与Lisp宏进行比较. F#3.0类型提供程序和Lisp宏似乎都允许用户代码在编译时执行,并引入了可用于编译器的新类型.任何人都可以阐明所涉及的问题和细微差别吗?

I've been reading about F# 3.0 type providers (e.g. here) and it seems that they are based on a kind of compile-time code generation. In that respect I was wondering how they compare against Lisp macros. It would seem that both F# 3.0 type providers and Lisp macros allow user code to execute at compile time and introduce new types available to the compiler. Can anyone shed some light on the issue and nuances involved?

推荐答案

F#类型提供程序与其他语言的元编程技术之间存在一些重叠,但我同意Daniel的看法,它们没有太多共同点. F#还有其他一些元编程技术,例如报价,可能更接近LISP宏.

There is some overlap between F# type providers and meta-programming techniques from other languages, but I agree with Daniel that they do not have much in common. F# has some other meta-programming techniques like quotations that are perhaps closer to LISP macros.

尤其是:

  • LISP宏通常用于转换表达式(您可以使用LISP表达式并对其进行解释或转换然后执行).请注意,该转换将LISP表达式作为输入-另一方面,类型提供程序只能接受非常有限的参数(字符串,整数).

  • LISP macros are typically used to transform expressions (you can take a LISP expression and either interpret it or transform it and then execute it). Note that the transformation takes a LISP expression as an input - on the other hand, type providers can only take very limited parameters (strings, integers).

报价更相似.它们可用于处理F#表达式-您可以将一段F#代码视为数据并对其进行解释或转换.转换采用F#表达式(的子集),但通常不执行它.

Quotations are more similar. They can be used to process F# expression - you can treat a piece of F# code as data and interpret it or transform it. The transformation takes (a sub-set of) an F# expression, but it typically does not execute it.

类型提供程序仅用于生成类型.由于LISP是动态键入的,因此这并不是LISP中真正存在的问题.但是,这是一种代码生成(您当然可以在LISP中完成的一种元编程形式).

Type providers are used purely to generate types. Since LISP is dynamically typed, this is not really a problem that you'd have in LISP. However, it is a sort of code-generation (a form of metaprogramming that you can certainly do in LISP).

这篇关于F#类型提供程序与Lisp宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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