[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Re: categories with parameters and defaults

From: Ralf Hemmecke
Subject: [Axiom-developer] Re: categories with parameters and defaults
Date: Tue, 14 Mar 2006 21:24:13 +0100
User-agent: Thunderbird 1.5 (X11/20051201)

On 03/14/2006 07:09 PM, Page, Bill wrote:
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))

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...

#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);
---- end

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
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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]