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

查看:69
本文介绍了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的Salary)和静态类型输入(例如,使其为双精度型或字符串型或其他类型).从本质上讲,这为您提供了静态类型对象模型的工具能力,并利用了各种动态或代码生成系统的易用性,并且在两者上均进行了一些改进. 成本"是某人必须编写填充程序库(类型提供程序"),但是许多此类提供程序非常通用(例如,会讲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/代码生成部分的类型提供程序.

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天全站免登陆