Scala类型系统与Haskell的缺点? [英] Disadvantages of Scala type system versus Haskell?

查看:319
本文介绍了Scala类型系统与Haskell的缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过Scala的类型系统被Java互操作性削弱,因此无法执行与Haskell类型系统相同的功能。这是真的?是因为类型擦除的弱点,还是我在各方面都是错误的?这是否与Scala没有类型类型的原因不同?

解析方案

最大的区别是Scala没有Hindley-Milner global类型推理,而是使用本地类型推断的形式,要求你指定方法参数的类型和重载函数或递归函数的返回类型。



这不是驱动的通过类型擦除或JVM的其他要求。这里所有可能的困难都可以克服,并且一直考虑到Jaskell - http://docs.codehaus .org / display / JASKELL / Home

HM推理在面向对象的上下文中不起作用。具体来说,当使用类型多态性时(与类型类的ad-hoc多态性相反)。这对于与其他Java库强有力的互操作性至关重要,并且(在较小程度上)从JVM获得最佳可能的优化。

这并不是真的有效哈斯克尔或斯卡拉拥有更强大的类型系统,只是它们不同。两种语言都在向不同的方向推进基于类型的编程的界限,并且每种语言都有其独特的优势,难以在其他方面重复。


I have read that Scala's type system is weakened by Java interoperability and therefore cannot perform some of the same powers as Haskell's type system. Is this true? Is the weakness because of type erasure, or am I wrong in every way? Is this difference the reason that Scala has no typeclasses?

解决方案

The big difference is that Scala doesn't have Hindley-Milner global type inference and instead uses a form of local type inference, requiring you to specify types for method parameters and the return type for overloaded or recursive functions.

This isn't driven by type erasure or by other requirements of the JVM. All possible difficulties here can be overcome, and have been, just consider Jaskell - http://docs.codehaus.org/display/JASKELL/Home

H-M inference doesn't work in an object-oriented context. Specifically, when type-polymorphism is used (as opposed to the ad-hoc polymorphism of type classes). This is crucial for strong interop with other Java libraries, and (to a lesser extent) to get the best possible optimisation from the JVM.

It's not really valid to state that either Haskell or Scala has a stronger type system, just that they are different. Both languages are pushing the boundaries for type-based programming in different directions, and each language has unique strengths that are hard to duplicate in the other.

这篇关于Scala类型系统与Haskell的缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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