[Haskell-cafe] Very silly

Tommy M. McGuire mcguire at crsr.net
Mon Oct 13 23:32:30 EDT 2008


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...

-- 
Tommy M. McGuire
mcguire at crsr.net


More information about the Haskell-Cafe mailing list