So I was looking through your implementation of the felix STL wrapper, 
and I wanted to see if I could implement the new iterator concepts from 
boost:

http://www.boost.org/libs/iterator/doc/new-iter-concepts.html

I ran into a couple issues though. The spec says that readable iterators 
should reference should deref into the element type (eg: "fun deref: it 
-> t") and lvalue iterators should deref into a reference of the element 
type ("fun deref: it -> lvalue[t]"). Now, in c++, we can automatically 
cast a reference into a concrete type, so you could just implement deref 
as the lvalue iterator for both function types. In felix though, I don't 
think works. We could use function overloading, but that would force us 
to specify the type. Would it be valid to do what we do for arrays, and 
have:

fun deref: it -> t = "...";
fun deref: lvalue[it] -> lvalue[t] = "...";

?

Also, when should we be using lvalues, and felix pointers? If lvalues 
are really just a c++ optimization like I mentioned in the last email, 
then shouldn't we be using felix pointers in the standard library?

Finally, here's what I got so far. Other than the lvalue issues, I'm 
having trouble uniquely describing the forward traversal iterator. 
According to the docs, it has a default constructor, and it has a 
difference_type. Since we can't yet embed a type in a typeclass, I'm not 
sure how to model this. Also, I don't exactly understand how it can be 
used with non-ordered structures (but that's a separate discussion. 
Anyway, here it is:


// value access

typeclass Readable_iterator[it,t] {
 virtual fun deref: it -> t;
}

typeclass Writable_iterator[it,t] {
 virtual proc store: &it -> t;
}

typeclass Swappable_iterator[it,t] {
 virtual proc iter_swap: &it -> ⁢
}

typeclass Lvalue_iterator[it,t] {
 virtual fun deref: &it -> &t;
}

instance[it,t with Readable_iterator[it,t], Writable_iterator[it,t]] 
Swappable_iterator[it,t] {
 virtual proc iter_swap (x:&it) (y:&it) {
   val tmp = deref x;
   store x$ deref y;
   store y tmp;
 }
}

instance[it,t with Lvalue_iterator[it,t], Writable_iterator[it,t]] 
Swappable_iterator[it,t] {
 virtual proc iter_swap (x:&it) (y:&it) {
   val tmp = deref x;
   store x$ deref y;
   store y tmp;
 }
}



// traversal

typeclass Incrementable_traversal_iterator[it,t] {
 open Forward[it];
}

typeclass Single_pass_traversal_iterator[it,t] {
 open Incrementable_traversal_iterator[it,t];
 open Eq[it];
}

typeclass Forward_traversal_iterator[it,t] {
 open Single_pass_traversal_iterator[it,t];
 // not sure how to symbolize that it can do
 // difference_type stuff  without providing any interface
 virtual type difference_type; // not valid
}

typeclass Bidirectional_traversal_iterator[it,t] {
 open Forward_traversal_iterator[it,t];
 open Bidirectional[it,t];
}

typeclass Random_access_traversal_iterator[it,t] {
 open Bidirectional_iterator[it,t];
 open Tord[it];

 virtual fun add (r:it, n:difference_type) = {
   var m = n;
   if m >= 0 do
     while m-- do
       ++r;
     done;
   else
     while m++ do
       --r;
     done;
   done;
   return r;
 }
 virtual proc pluseq (r:lvalue[it], n:difference_type) = { r = r + n; }
 virtual proc pluseq (n:difference_type, r:lvalue[it]) = { r = r + n; }

 virtual fun sub (r:it, n:difference_type) => r + (-n);
 virtual proc pluseq (r:lvalue[it], n:difference_type) = { r = r - n; }

 virtual fun sub: it * it -> it;

 virtual fun subscript: it * n:difference_type -> t;
 virtual fun subscript: lvalue[it] * difference_type -> lvalue[t];
}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to