F# 类型提供程序,它们是如何工作的 [英] F# type providers, how do they work

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

问题描述

在观看 Don Symes 的 pdc 视频后,我不太了解类型提供程序http://player.microsoftpdc.com/Session/04092962-4ed1-42c6-be07-203d42115274

I don't quite get type providers after watching Don Symes's pdc video http://player.microsoftpdc.com/Session/04092962-4ed1-42c6-be07-203d42115274

我是否理解正确.您可以为 Twitter、Excel 准备现成的类型提供程序...

Do I understand this correctly. You can get ready made type providers for Twitter, Excel...

如果我有自定义 Xml 结构,我是否需要为此实现自己的类型提供程序,这与创建自己的自定义映射器有何不同?

What if I have a custom Xml structure, do I need to implement my own type provider for that and how is this different from creating my own custom mapper?

推荐答案

假设你有一些任意的数据实体.在本例中,假设它是一个电子表格.

Say you have some arbitrary data entity out in the world. For this example, let's say it's a spreadsheet.

假设您有某种方法可以获取/推断该数据的架构/元数据 - 也就是说,您可以知道类型(例如双精度与字符串)和关系(例如,此列表示薪水")和元数据(例如此表适用于 2009 年 6 月的预算).

Let's also say you have some way to get/infer schema/metadata for that data - that is, you can know types (e.g. double versus string) and relationships (e.g. this column means 'salary') and metadata (e.g. this sheet is for the June 2009 budget).

类型提供程序允许您编写一种填充库",该库了解某种数据实体(例如电子表格),并将该库用作编译器/IDE 工具链的一部分,以便您可以编写类似

Type providers lets you code up a kind of 'shim library' that knows about some kind of data entity (e.g. a spreadsheet) and use that library as part of the compiler/IDE toolchain so that you can write code like

mySpreadsheet.ByRowAndColumn.C4

或其他东西,并获得 Intellisense(自动完成)和工具提示(例如,将单元格 C4 描述为 Bob 的薪水)和静态类型(例如,将其设为双精度或字符串或其他任何内容).本质上,这为您提供了静态类型对象模型的工具可供性,以及各种动态或代码生成系统的易用性杠杆,并在两者上都有一些改进.成本"是有人必须编写 shim 库(类型提供程序"),但许多此类提供程序非常通用(例如,会使用 OData 或 Excel 或 WMI 或诸如此类的内容),因此只有少数类型提供程序库通过静态类型和一流的工具支持,以您的编程语言提供世界上的大量数据.

or something, and get Intellisense (autocompletion) and tooltips (e.g. describing cell C4 as Salary for Bob) and static typing (e.g. have it be a double or a string or whatever it is). Essentially this gives you the tooling affordances of statically-typed object models with the ease-of-use leverage of various dynamic or code-generation systems, with some improvements on both. The 'cost' is that someone has to write the shim library (the 'type provider'), but many such providers are very general (e.g. one that speaks OData or Excel or WMI or whatnot) and so a small handful of type provider libraries makes vast quantities of the world's data available in your programming language with static typing and first-class tooling support.

该架构是一个开放的编译器,其中提供者作者实现了一个小接口,允许他们将新名称/类型注入到编程上下文中.类型提供程序可能只是您传递给编译器的另一个库(项目中的引用,-r-ed),带有额外的元数据,将其标记为参与编译/IDE 的类型提供程序/codegen 开发部分.

The architecture is an open compiler, where provider-authors implement a small interface that allows them to inject new names/types into the programming context. A type provider might be just another library you pass to the compiler (a reference in your project, -r-ed), with extra metadata that marks it as a type provider that participates in the compilation/IDE/codegen portions of development.

我不知道您的 xml 示例中的自定义映射器"究竟是什么以进行比较.

I don't know exactly what a "custom mapper" is in your xml example to draw a comparison.

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

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