Boost logo

Boost :

From: Mat Marcus (mat-boost_at_[hidden])
Date: 2003-11-14 11:15:03

--On Thursday, November 13, 2003 10:45 PM -0500 Brian McNamara
<lorgon_at_[hidden]> wrote:

> On Thu, Nov 13, 2003 at 04:54:20PM -1000, David Abrahams wrote:
>> "Brock Peabody" <brock.peabody_at_[hidden]> writes:
>> > template <typename T> T* clone(const T& t) {
>> > return mpl::if_<
>> > has_clone_function<T>,
>> > use_clone_function,
>> > use_copy_constructor
>> > > ::type::clone(t);
>> > }
>> This sort of thing really worries me in generic code, because the
>> name alone is not enough to identify the semantics. It's one thing
>> to say, "if this thing has a clone function AND its signature
>> contains a special type that you can only know about if you also
>> know about the way my library looks for clone functions, then...",
>> but when you just check for a clone function as you do above,
>> you're relying on everyone having an agreement about the meaning of
>> "clone".
>> OK, so maybe clone is more likely to be agreed upon than the
>> semantics of most other member function names. I hope you get my
>> point, though. It's easy to create really broken "generic" designs
>> with these sorts of tests. You have to use them very carefully.
> "Me too."
> In my opinion, "named conformance" is the right way to design most
> interfaces, whereas "structural conformance" (as above) is the wrong
> way.


Named conformance worries me, though I haven't programmed much in
Haskell yet. One question I have is: who writes the type classes (or
whatever you want to call these things)? I can't imagine it is the
library author since the generic (meta-)algorithms are meant to be
used with an unbounded set of types(, metafunctions, etc.). But a
library's usability would seem to suffer if the user has to manually
assert conformance to various concepts before calling generic
algorithms. A hybrid approach where the library author provides the
named conformance for "common types" doesn't seem to help. I want the
generic algorithm to be written in such a way that the compiler can
check conformance for me. Are you really worried about accidental
structural conformance? How do things work in practice in Haskell?

 - Mat

Boost list run by bdawes at, gregod at, cpdaniel at, john at