|
Re: A Problem involving the Syntax of Concepts in Heron
|
Posted: Nov 7, 2005 9:22 AM
|
|
> > To take a an example: Say you > > have a concept Addable, which is defined like this > > (made-up syntax, but similar to the C++ concept > > proposals): > > > > concept Addable > > { > > Element operator+(Element,Element); > > } > > > > This concept can be matched ("modeled", in "concept > > speak") by types such as "int", "float", > > "SomeClassWithOverloadedOperatorPlus", etc. > > > > In other words, there's no "interface" you derive from, > to > > declare conformance to a concept, and as such, it can > be > > used for built-in types, as well. Moreover, the above > > signature is a "pseudo-signature": A concept with a > > signature like "bool something()" can be modeled by a > type > > with a function with the name "something", but it > doesn't > > have to return exactly bool: it can return something > > _convertible_ to bool. > > That definition of a concept horribly sounds like > strangely statified duck-typing that doesn't want to > accept it's nature
Could you please define "duck-typing", so we know what you mean by it? My understanding was that C++ templates _are_ a form of duck typing: the matching is done based on syntax, rather than a specific signature. See this article: "Templates and Duck Typing" (http://devnet.developerpipeline.com/documents/s=9843/q=1/cuj0506koenig/)
The problem with duck typing is that you can't specify any constraints in the interface; it matches everything, and only potentially crashes in the implementation, not at the call-site, where the error arguably are (incompatible types used for the arguments). That's where "concepts", or "constrained generecity" (which is also found in some other languages, like Ada, Haskell and ML) come in, as they allow you to specify the constraints a type must meet, that may be checked at the call site (or instantiation site, for class templates).
Templates (and Herons concepts, I assume) are matched at compile-time, while in dynamically typed languages, the matching usually happens at run-time.
I'm wondering what you mean by "its nature", because it seems to me different terms are used for the same thing, and/or have different meaning to different people, making discussions confusing. The terms I used above, and Christopher uses, like "concept", "refinement" and "model", are specific terms in "generic programming" terminology, that I used to try to avoid misunderstandings. Of course, that's only successful if the terms are understood by others, as well. :)
Therefore, we may be talking about the same thing (and not something "trying to escape its nature" :) ), but I guess it goes to show that "duck typing" may mean different things to different people.
Regards,
Terje
|
|