Scala中的.NET / CLR物化仿制药 [英] Reified generics in Scala on .NET/CLR

查看:224
本文介绍了Scala中的.NET / CLR物化仿制药的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

斯卡拉(至少在 JVM )使用的type擦除对Java的兼容性。该<一href="http://programmers.stackexchange.com/questions/55047/what-is-the-greatest-design-flaw-you-have-faced-in-any-programming-language">feature是<一个href="http://stackoverflow.com/questions/1357906/is-it-possible-for-scala-to-have-reified-generics-without-changing-the-jvm">widely <一href="http://stackoverflow.com/questions/8582479/overloading-generic-event-handlers-in-scala">held <一href="http://stackoverflow.com/questions/1094173/how-do-i-get-around-type-erasure-on-scala-or-why-cant-i-get-the-type-paramete">to 。 <一href="http://stackoverflow.com/questions/1357906/is-it-possible-for-scala-to-have-reified-generics-without-changing-the-jvm">Fixing这将是很难在JVM上。

Scala (at least on the JVM) uses type erasure for Java compatibility. This feature is widely held to suck. Fixing this would be difficult on the JVM.

<一个href="https://en.wikipedia.org/w/index.php?title=Comparison_of_C_Sharp_and_Java&oldid=503563938#Type_erasure_versus_reified_generics"相对=nofollow>与此相反的JVM的情况下,.NET支持具体化泛型。确实的 Scala的.NET实现使用它们?如果不是,可能吧,否则什么问题都用物化的原因?

In contrast to the JVM situation, .NET supports reified generics. Does Scala's .NET implementation use them? If not, could it, or else what issues would using reification cause?

推荐答案

这是正在进行的工作,不小心打破JVM和.NET之间Scala的语义。

It's work in progress, carefully not to break Scala semantics between JVM and .NET.

我问这个问题,早在2011年斯卡拉-工具,邮件列表,答案由米格尔·加西亚,他勾勒出大画面给出:

I asked this question back in 2011 on the scala-tools mailinglist and the answer is given by Miguel Garcia in which he outlines the big picture:

一些报价:

(1)Scala.Net preVIEW目前能做什么。正如你已经注意到了,   擦除阶段也运行作为管道的一部分。这是一个   的preVIEW版的功能,被列入特征的有   因为对CLR泛型支持是现在还没有(关于这一点   下面)。然而,有一个很大的优势,运行的JVM式   擦除在Scala.Net:所有的Scala程序在那里,依靠   Scala库已经可以被编译,而不是等待的.Net,   为CLR泛型做好准备。这依赖于Java JDK那些方案   也可以被编译,受到IKVM支持JDK的API的   问题1]。

(1) What the Scala.Net preview currently does. As you have noticed, the erasure phase also runs as part of the pipeline. This is a "feature" of the preview version, a "feature" that had to be included because support for CLR Generics wasn't there yet (more on this below). There is however one big advantage to running JVM-style erasure in Scala.Net: all the Scala programs out there that rely on the Scala library can already be compiled on .Net, instead of waiting for CLR Generics to be ready. Those programs that rely on the Java JDK can also be compiled, subject to IKVM support of the JDK APIs in question [1].

(2)在Scala.Net为CLR泛型支持。主要动机   支持它获得的互操作性与现有的组件。在   获得互操作性,将会注意不能割舍   从Scala的语义。换句话说,任何有效的Scala程序将   运行并产生对JVM和.NET相同的结果。这给我们带来   在正在进行的工作[2]。最初的原型仅处理C#   斯卡拉的子集。所以现在我解决了休息。它比更多的工作   最初预期,但它覆盖整个语言是很重要的。

(2) Support for CLR Generics in Scala.Net. The main motivation to support it is gaining interoperability with existing assemblies. In gaining that interoperability, care will be taken not to break away from Scala semantics. In other words, any valid Scala program is going to run and produce the same results on JVM and .NET. Which brings us to the work in progress [2]. The initial prototype handles only the C# subset of Scala. So now I'm addressing the rest. It's more work than initially anticipated but it's important to cover the whole language.

这几个意见,   特别是原生的问题。是的,CLR组件可以使用EX preSS   本土INT(在不同的CPU不同尺寸)的,P / Invoke的   C函数出口的一个.dll和这样的。 Scala.Net的目的不是做   低层次的挂羊头卖狗肉。感兴趣的组件互操作性   在公共语言规范的水平,即量力而行   通常在任何C#,VB.NET等编译器(常,即获得   除非使用[的DllImport]的属性和相关的C ++ - ISMS)

A few more comments regarding interop with .NET assemblies, in particular native issues. Yes, CLR assemblies can express using "native int" (different sizes on different CPUs), P/Invoke of C-functions exported by a .dll and such. Scala.Net does not aim to do that low-level trickery. The assembly interoperability of interest is at the level of "Common Language Specification", i.e. what one normally obtains from any C#, VB.NET, etc. compiler ("normally" i.e. unless using "[DllImport]" attributes and related C++-isms).

从CLI规格报价:

---开始报价---通用语言规范(CLS) - CLS的是(语言设计者和框架之间的协议是,   类库)的设计师。它规定了CTS的一个子集(共   类型系统)和一组使用约定的。   语言提供他们的用户访问的最大能力   通过实现在CTS的是至少那些部分的框架   华彩的一部分。类似地,框架将被最广泛使用的,如果   他们公开导出方面(例如,类,接口,方法,   和字段)只使用是CLS的部分类型和坚持   CLS的约定。   ---结束引用---

--- start quote --- The Common Language Specification (CLS) -- The CLS is an agreement between language designers and framework (that is, class library) designers. It specifies a subset of the CTS (Common Type System) and a set of usage conventions. Languages provide their users the greatest ability to access frameworks by implementing at least those parts of the CTS that are part of the CLS. Similarly, frameworks will be most widely used if their publicly exported aspects (e.g., classes, interfaces, methods, and fields) use only types that are part of the CLS and that adhere to the CLS conventions. --- end quote ---

看到整个主题:

https://groups.google.com/forum/ ?fromgroups#!话题/斯卡拉-工具/ JDjstK1_uvM

这篇关于Scala中的.NET / CLR物化仿制药的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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