On 27/06/2009, at 7:14 AM, Erick Tryzelaar wrote: >> >> http://okmij.org/ftp/papers/LL3-collections-enumerators.txt >> >> I wonder if we could draw any inspiration from it. > > > I found a partial ocaml implementation of this:
Oleg partially misses the point I think. C++ style iterators are hard to write because they have to maintain complex position state, but the whole point is that they can then be used by master code, as opposed to the slave (callback) code required by a fold. In the fold, the client code has to maintain state in an object. In master code some of the state is maintained using the stack, and therefore is synchronised properly with control flow. With generators, C++ style iterators are easy to write, since they use the stack too: a generator is master code. The question then reduces to whether master or slave code is better. For simple jobs, a slave is better, Oleg identifies some of the reasons (resource leakage, encapsulation etc). However for a complex job, masters are better because part of the work is done by the control-flow/stack integration the language provides. In C++ however there is an additional argument for iterators: client code is polyadic (via use of templates). Template clients can be written independent of the container, since iterators hide the container type. In Ocaml the inability to do this is a major bug-bear. You have to use Hashtbl.iter or List.iter or Set.iter or whatever. In C++ you just call container.begin() Of course this is only "textually polyadic". -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language