[Haskell-cafe] Very silly

Brad Larsen brad.larsen at gmail.com
Tue Oct 14 01:31:38 EDT 2008

On Mon, 13 Oct 2008 23:32:30 -0400, Tommy M. McGuire <mcguire at crsr.net> wrote:

> Andrew Coppin wrote:
>> Bulat Ziganshin wrote:
>>> people that make critique on haskell type classes, don't take into
>>> account that it's unlike C++ templates, implemented via run-time
>>> dictionaries and other modules may define new instances
>> Personally, I have no clue how C++ templates work [yet]. (As in, I'm
>> learning C++, but I haven't got to that chapter yet.)
>> Some guy told me that templates are "the best feature in the language",
>> and proceeded to show me a huge chunk of highly complex-looking code
>> which is approximately equivilent to
>>  join :: Array x -> Array x -> Array x
>> I was unimpressed.
>> Actually, that's a lie. I was impressed that such a low-level language
>> could manage even that much abstraction. But I still prefer the Haskell
>> way...
> C++ values have sizes:
>    class foo {
>      int x;
>    };
> is half (ahem; make that "different from") the size of
>    class bar {
>      int x;
>      int y;
>    };
> As a result, doing parametric polymorphism requires duct taping
> something suspiciously similar to cpp macros to the type system.  Hence,
> how C++ templates work: weirdly.
> Java (and presumably C#) "generics" are very much like a weakened
> version of normal parametric polymorphism.  C++ templates are an attempt
> at the same thing in a completely different landscape.  I'd be willing
> to bet that Some Guy's code was very close to exactly equivalent to your
> join.
> Now, as to what C++ templates have to do with Haskell type classes, I
> dunno...

In the next C++ standard, type checking capabilities are being added to templates---"concepts" specify a set of operations a templated type must support.  See <http://en.wikipedia.org/wiki/C%2B%2B0x#Concepts>.  Seems somewhat similar to Haskell typeclasses to me, but perhaps the similarity is merely superficial. :-)

Brad Larsen

More information about the Haskell-Cafe mailing list