I don't like the STL iterator stuff much for Felix. So we have this  
little
problem:

typeclass Container [c,v]
{
   virtual fun len: c -> size;
   virtual fun empty(x: c): bool => len x == size(0);
}

typeclass Sequence[c,it,v] {
   inherit Eq[c];
   inherit Forward_iterator[it,v];
   inherit Container[c,v];
   virtual gen begin: c -> it;
   virtual gen end: c -> it;
   virtual proc erase: lvalue[c] * it;
   virtual proc erase_between: lvalue[c] * it * it;
   virtual proc clear: lvalue[c];
   virtual fun fold[i] (f:i->v->i) (var acc:i) (x:c): i = {
     var s = begin x; var e = end x;
     whilst s != e do acc = f acc (*s); ++s; done;
     return acc;
   }
}

Now, for varray, I'd like the Container typeclass to have virtual iter,
from which a derived function fold_left can be defined. The iter
instance would be:

   proc iter[T] (_f:T->void) (x:varray[T]) {
     var i : ulong;

     if len(x) > 0ul do forall i in 0ul upto len(x) - 1ul do
       _f x.[i]
     done done
   }

and the definition of fold_left is standard for all containers
(just iter over the assignment init = f(init,element)).

The problem is that Sequence already defines fold_left
in terms of STL iterators. Ideally, we'd change this so
it defined iter, and uses Container's definition of fold_left.
In fact, fold_left isn't even virtual. But that doesn't change
the problem: then we have "iter" virtual in Container,
and we want to define it in Sequence.

But we can't. Sequence is a class derived from Container,
but it isn't an instance, so a defining function would clash
with Container's iter instead of instantiating it.



--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to