| > What's a language you think does generic programming 'right'? The most obvious examples are ML and its derivatives. > C++ has good support for static / compile time ADTs (the STL is very much built around the idea) and also supports 'runtime' ADTs through interfaces. In neither case is friend needed to abstract over types. The STL is built around ADTs in spite of the language's lack of support. If C++ had an actual notion of abstract types, then templates could be type-checked against ADT specifications (so-called “concepts”), rather than having to wait until instantiation time. > In neither case is friend needed to abstract over types. You can't encapsulate a single abstraction providing two or more ADTs without using `friend`. That's a fact. > Static polymorphism in C++ currently relies on duck typing but this is what the Concepts TS is addressing. This is a reply to the wrong thing. Concepts are ADT specifications, not object specifications. |
I'm reasonably familiar with F# but I know that's strayed quite far from its ML roots and its generics are constrained to some degree by what the CLI supports. For the kinds of generic programming that C++ does well it's not clear to me where the ML style is superior. Can you give some specifics?
> If C++ had an actual notion of abstract types, then templates could be type-checked against ADT specifications (so-called “concepts”), rather than having to wait until instantiation time.
Yep, that's why everyone wants Concepts to be standardized.
> You can't encapsulate a single abstraction providing two or more ADTs without using `friend`. That's a fact.
I'm still not clear what the issue is here. A C++ class can implement multiple interfaces for dynamic polymorphism without using friend and can implement more than one 'concept' for static polymorphism without using friend. Can you explain what you mean in more detail?
> This is a reply to the wrong thing. Concepts are ADT specifications, not object specifications.
Are you talking about something like Go interfaces? For my use cases static polymorphism is generally preferable to dynamic polymorphism and in those cases where dynamic polymorphism is desirable C++ style interfaces are often sufficient. When the need arises for something like a Go interface in C++ people usually use type erasure but implementing that currently requires a bit more boilerplate than would be ideal (though there are libraries that help). That's something that could be solved in the future by something like Herb Sutter's metaclass proposal. Perhaps I'm still not understanding your point though.