Scala 特性和 C++ 之间的区别概念
Scala 特征 Haskell 类型类和 C++0x 概念之间有什么区别?
就像下面这个例子,观察者声明一个抽象成员 receiveUpdate 观察者实际上是一种“匿名”类型或结构类型。
package observer
trait Subject {
type Observer = { def receiveUpdate(subject: Any) }
private var observers = List[Observer]()
def addObserver(observer:Observer) = observers ::= observer
def notifyObservers = observers foreach (_.receiveUpdate(this))
}
What is the difference between Scala traits Haskell type class and C++0x Concepts?
Like in this example below where Observer declare an abstract members receiveUpdate
Observer is in fact a “anonymous” types or Structural types.
package observer
trait Subject {
type Observer = { def receiveUpdate(subject: Any) }
private var observers = List[Observer]()
def addObserver(observer:Observer) = observers ::= observer
def notifyObservers = observers foreach (_.receiveUpdate(this))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,它们中只有两个有一些共同点,但不是很多,那就是概念和类型类。本文已经对两者进行了比较:C++ 概念的比较和 Haskell 类型类
So only two of them have something in common but not by much, that is Concepts and Type-classes. There already has been comparisons between the two in this paper: A comparison of C++ concepts and Haskell type classes