views:

166

answers:

2

Is it possible to implement Haskell typeclasses in C++? If yes, then how?

+4  A: 

There's a few papers on this, which might be useful as background reading:

Don Stewart
Excellent papers. Thanks.
Sunil Kothari
Am I the only one to notice that the OP's name is similar to the name of the first author of "C++ templates/traits versus Haskell type classes" ?
Matthieu M.
+1 for the second link, a categorization of the required features is very interesting indeed.
Matthieu M.
First paper: "C++ templates/traits versus Haskell type classes". There is an error at page 9 (Example 6), code is expressed in the body of a `struct`. It seems to me that the author have only an approximative knowledge of C++ and this shows in the examples.
Matthieu M.
+1  A: 

The similar mechanism in C++ is called "concepts". The idea is to define a typeclass by defining the requirements of any type belonging to that class. C++ iterators make extensive use of concepts, and C++0x had intended to support direct syntax for them (rather than the indirect template tricks to perform concept checks C++ currently employs), but it appears this support has been dropped from the standard.

John