views:

117

answers:

1

What is the difference between Scala traits Haskell type class and C++0x Concepts?

+5  A: 
  • Concepts are not coming to C++0x, they've been removed in the last few versions of the draft spec.
  • Type-classes where originally designed for bounded quantification of parametric polymorphism (generic constraints, "forall x such that x is an...") and a mechanism to provide ad-hoc polymorphism for a totally type inferred language in a less ad-hoc manner.
  • Concepts are also for bounded quantification of parametric polymorphism and provide concept overloading, which makes up for the lack of partial specializations of template functions in C++. They where originally designed to deal with template error message problem in C++.
  • Traits are mechanism to mix-in behaviors without using multiple-inheritance.

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

snk_kid
I don't think that #3 is a big issue, since everybody just uses a static friend class implementation and gets the same effect anyway. In addition, it would be bloody easier just to allow partial spec of functions than to go through the whole concepts thing.
DeadMG
@DeadMG: what issue? get the same effect of what? you can emulate partial specialization of template functions using tag type dispatching techniques, that is exactly what is being currently done with iterator concepts and generic algorithms for 'specialized' algorithms depending on the iterator/container type traits. Anyway I was never trying to get into any debate about issues, that is just diverging from the main topic.
snk_kid
It is my understanding that Scala Traits and Haskell type classe are very similar.Trait can not only be used to mix-in behaviors but also to define a set of contracts across unrelated types using parametric polymorphism.http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html
skyde