Comment

Comment by SamReidHughes_

C++ requires that all overloaded versions exist at compile time; Haskell allows them to exist at runtime. For example, in Haskell you can make a datatype like

    data Foo a = Blah a | Bar (Foo [a])
and you'll have no trouble making a function "showFoo :: Show a => Foo a -> String" using straightforward programming. If you try to do that in C++ you'll get infinite template recursion.

Also, C++ templates don't restrict you to match the right type signatures, the way Haskell typeclasses do.

But other than that, they are pretty much the same kind of thing and are used in the same way.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton