[Aldor-l] Segfaulting program

Martin Rubey martin.rubey at univie.ac.at
Sat Aug 16 15:40:20 EDT 2008


Dear all,

the program below currently segfaults (at least with aldor 1.0.3, at the point
where the default implementation for binaryRepeat tries to call op.

I wonder whether

define MyAddMonoid: Category == with {
        +: (%, %) -> %;
        MyMonoid(%, +$%);
        binaryAdd: (Integer, %) -> %;
        default binaryAdd(n: Integer, x: %): % == binaryRepeat(n, x);
}

is valid Aldor and it's just a compiler bug, or whether it's invalid for some
reason?

Furthermore, I wonder what binaryAdd$MyInteger and binaryTimes$MyInteger should
do, in case it were valid Aldor.

Martin


#include "aldor"
#include "aldorio"

define MyMonoid(T: Type, op: (T, T) -> T): Category == with {
        binaryRepeat: (Integer, T) -> T;
        default {
                binaryRepeat(n: Integer, x: T): T == {
                        if n = 1 then return x
                        else op(x, binaryRepeat(n-1, x))
                }
        }
}

define MyAddMonoid: Category == with {
        +: (%, %) -> %;
        MyMonoid(%, +$%);
        binaryAdd: (Integer, %) -> %;
        default binaryAdd(n: Integer, x: %): % == binaryRepeat(n, x);
}

define MyMulMonoid: Category == with {
        *: (%, %) -> %;
        MyMonoid(%, *);
        binaryTimes: (Integer, %) -> %;
        default binaryTimes(n: Integer, x: %): % == binaryRepeat(n, x);
}

MyInteger: Join(MyAddMonoid, MyMulMonoid) with {
        *: (%, %) -> %;
        1: %;
        OutputType;
        } == Integer add;

main(): () == {
        import from Character, TextWriter, Integer, MyInteger;
        stdout << binaryAdd(2, 1) << newline;
        stdout << binaryTimes(2, 1) << newline;
}
        
main();




More information about the Aldor-l mailing list