[Aldor-l] Generators

Bill Page bill.page at newsynthesis.org
Tue Nov 13 09:04:30 EST 2007


> Martin Rubey wrote:
> > Peter Broadbery writes:
> >>> ...
> >>> Consequently they can be used in type expressions and having dependent
> >>> crosses as "for" indices should be allowed.
> >
> > Oh, that's interesting.  So
> >
> >         for i in g repeat {
> >                 (a: MachineInteger, b: SmallPrimeField(a)) == i;
> >                 stdout << a << newline;
> >                 stdout << b << newline;
> >         }
> >
> > should be OK?  But it doesn't work with -DDEBUG...
> >
> >> Unfortunately, the compiler isn't keen on them being used in types.
> >>
> >> "bug2.as", line 10:        (x, 0$SPF(x)) for x in 1..10;
> >>                     .........................^
> >> [L10 C26] #1 (Error) `x' is used in a type, so must be constant,
> >> and so cannot be assigned to.
> >>
> >> This seems to be built into scobind.c. I'll hit it with a stick & see
> >> what happens..
> >
> > That would be great!
> >
> > Another mistery, at least to me:  Bill sent this snippet:
> >
> >        stdout << "test dependent:" << newline;
> >        for (a:MachineInteger, b:SmallPrimeField a) in g repeat {
> >                stdout << a << " " << b << newline;
> >        }
> >
> > root at sage:~/aldor-src/aldor/install/aldor# aldor -fx  -lalgebra
> > -laldor crossiterator.as
> > "crossiterator.as", line 63:
> >        for (a:MachineInteger, b:SmallPrimeField a) in g repeat {
> > ............^
> > [L63 C13] #1 (Error) `a' is used in a type, so must be constant,
> > and so cannot be assigned to.
> >
> > Any idea why it's C13 here and C26 above?
>

On 11/13/07, Laurentiu Dragan wrote:

> For type safety, types must constant. By allowing types to change
> at runtime, a variable could have different types at runtime which
> makes type checking at compile time impossible.
>

That is true but I think it can be properly argued that in all cases
above, the type of 'b'  in

  for (a:MachineInteger, b:SmallPrimeField a) in g repeat {

and

  for i in g repeat {
          (a: MachineInteger, b: SmallPrimeField(a)) == i;

and the type of 'SPF(x)' in

   for (x, 0$SPF(x)) for x in 1..10;

is constant *in this context*, i.e. with the tuple ( ... ) and within
the block { ... }. In other cases the Aldor compiler does compile code
which has types that are constant only within a given context.

Regards,
Bill Page.



More information about the Aldor-l mailing list