On 03/14/2006 07:09 PM, Page, Bill wrote:
Ralf,
On Tuesday, March 14, 2006 9:58 AM you wrote:
I wrote:
I suppose it would be better to write:
default {
Rep == T;
square(t: %): % == per(m(rep(t), rep(t))
}
NOOOO.... PLEASE DONT USE ANY REPRESENTATION IN A CATEGORY.
The 'Rep' is not a representation in a category. It is in
the default implementation of 'square' which is implemented
in some domain which satisfies this category.
Perhaps you might object that such defaults are best thought
of as virtual packages. I agree that in SPAD that that is how
they are implemented. But we still need to worry about
representation since ultimately they are used in the context
of some domain which satisfies the corresponding category.
Suppose someone later implements your category and just
uses some other representation than T.
Say what? ;) This default clause is just part of the
definition of a category where T is a parameter of the category,
e.g. Martin's 'MyMonoid'. What type T represents depends on how
this category is "called", e.g. in
MyMonoid(Integer, *$Integer)
T is Integer, so we have the representation
Rep == Integer;
In other cases we have other representations
Let me give explicit code...
--- RepInCat.as
#include "aldor"
#include "aldorio"
define CatA(T: Type, foo: T->T): Category == OutputType with {
foo: () -> %;
bar: % -> %;
default {
Rep == T;
bar(x: %): % == per foo rep x;
}
}
DomA: CatA(Integer, -$Integer) == add {
Rep == List Boolean; import from Rep;
foo(): % == per [true, false];
(p: TextWriter) << (x: %): TextWriter == p << rep x;
}
main(): () == {
import from DomA;
stdout << foo() << newline; flush!(stdout);
stdout << bar(foo()) << newline; flush!(stdout);
}
main();
---- end RepInCat.as
By fixing the "Rep" in the category, you require that the compiler has
to reject the definition of DomA. Currently the Aldor compiler does not
do that.
And so the above program compiles and yields as output...
aldor -laldor -fx RepInCat.as
RepInCat
[T,F]
Segmentation fault
As expected, right?
If you want the compiler to fix the representation in the category, we
are back to the multiple inheritance problem.
Ralf
_______________________________________________
Axiom-developer mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/axiom-developer