[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sather: templates necessary?
From: |
Eray Ozkural |
Subject: |
Re: Sather: templates necessary? |
Date: |
Wed, 11 Oct 2000 03:02:26 +0300 |
Norbert Nemec wrote:
>
> Be careful: 'templates' as known in C++ and 'parameterized classes' in
> Sather are two distinct concepts: templates are something like a
> cut'n'paste mechanism. A template really only becomes a meaning at
> instantiation time. It is not "complete" before you tell the compiler
> what it should use for the template parameters.
Err. no. Templates in C++ are not different from generic constructs
in other languages essentially. The original cfront implementation
did textual substitution to implement templates but that is just
a matter of implementation. In current compilers, more intelligent
strategies are employed to that end.
> One of the results is
> that, quite often, you get ton's of error messages once use first
> instantiate a template, just because they could never be checked before
> by the compiler.
Not that way for a long time, because compilers check templates
for errors before they are instantiated.
>
> Parameterized classes on the other hand, could (if the compiler did
> work properly, which ours probably does not at the moment) even be
> compiled without being instantiated: Since every parameter of the class
> is known to fit some abstract class ($OB if none is specified), every
> occurrence could be just handled as a reference to a object of that
> type. Therefore you could have a precompiled library containing code of
> a parameterized class. Of course there is much optimization possible
> once the the class is instantiated, but that's another matter.
>
Correct. But in a true C++ implementation (which I believe does not
really exist except perhaps IBM's C++ compilation system which had
a few features I gasped at), the same thing should be done. The output
of a generic library does not go into an object, but a generic object
which is partially compiled and parametrized code. The compiler saturates
the lacking parameters and proceeds with full code generation and
optimization. The generic objects would probably be a dump of internal
program representation (also called intermediate language :)
Abstract classes can even be implemented (approximately)
in C++ with some ugly-looking tweaks. The GNU libstdc++ v3 has
some IIRC.
> > Secondly, is multiple-polymorphism possible in Sather?
> > Multi-methods?
>
> What is it? Sounds strange to my ears, but it may well be, it is just
> called differently or included in some larger concept.
>
multiple polymorphism is the generalization of polymorphism. A simple
example would be (in pseudo code)
Display d;
Shape s := new Rectangle;
Brush b := new Airbrush;
...
d.draw(s,b); -- polymorphic on s and b, and not d!
Here is an example of a double-dispatch. A multiply polymorphic
function call interface would allow polymorphism on any number of
parameters not just "self"
Thanks,
--
Eray (exa) Ozkural
Comp. Sci. Dept., Bilkent University, Ankara
e-mail: address@hidden
www: http://www.cs.bilkent.edu.tr/~erayo
- Re: Sather: templates necessary?, Norbert Nemec, 2000/10/10
- Re: Sather: templates necessary?,
Eray Ozkural <=
- Re: Sather: templates necessary?, Norbert Nemec, 2000/10/12
- Re: Sather: templates necessary?, Norbert Nemec, 2000/10/15
- Re: Sather: templates necessary?, Eray Ozkural, 2000/10/15
- Re: Sather: templates necessary?, Eray Ozkural, 2000/10/15
- Re: Sather: templates necessary?, Norbert Nemec, 2000/10/16
- Re: Sather: templates necessary?, Eray Ozkural, 2000/10/16