Feature request: interfaces declare types
Henning Hasemann
hhasemann at web.de
Wed May 23 23:38:38 PDT 2007
On Thu, 24 May 2007 07:49:50 +1000
Reiner Pope <some at address.com> wrote:
>
> My code doesn't entirely suit your use-case, but it does something similar:
>
> class Foo (ContainerType) {
> ContainerType someNumbers;
>
> int popNumber() {
> ContainerType.Iterator nr = someNumbers.firstIterator();
> ...
> }
> }
>
> Your given usage example is a long way from D's type system: interfaces
> are dynamic in nature, so you would expect the Iterator type specified
> by it only to be known dynamically. But when you use types, you have to
> know them statically.
The point with my example is working with a container you dont know the
explicit type of. Imagine some function returns a bunch of items like this:
Container(int) getMyItems();
Now you want to work with this bunch of items and you want to use iterators.
So your example doesnt seem to help me, because I need to know the Iterator type
in advance in order to use Container(). But if I knew that at that time
I knew the Container type as well, so I wouldnt have to work with the interface.
But I see the problem you mentioned:
If I have Container(int) a = getMyItems(); a.Iterator would be one type
and if I then do a = getSomeOtherItem(); a.Iterator might be another
which the type system shouldnt be able to handle because
that choice might depend on runtime cirumstances.
> I think what you are after would be better solved by some kind of Concepts.
Sorry I'm not sure I get what you mean with "some kind of Concepts", could
you be more specific?
Henning
--
GPG Public Key: http://keyserver.veridis.com:11371/search?q=0x41911851
Fingerprint: 344F 4072 F038 BB9E B35D E6AB DDD6 D36D 4191 1851
More information about the Digitalmars-d
mailing list