On Fri, Jun 26, 2009 at 3:01 PM, john
skaller<skal...@users.sourceforge.net> wrote:
>
> 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".


I'm not sure if I completely understand you. As far as I can tell,
this is a technique to turn folds into cursors, which you could use to
write your polyadic functions. For instance, we could take a cursor
and write:

let count c =
  let aux init c =
    match Lazy.force c with
    | None -> init
    | Some i, c -> aux (init + i) c
  in
  aux 0 c

And it should work with all cursors. I interpreted it as as long as
you can create continuations, you can convert folds into cursors.

I don't think Oleg is saying that folds are always better, but that by
default ASTs should provide enumerators and convert them into cursors
when they're needed. Are you more talking about the inefficiencies of
doing this instead of what c++ does? I assume it's much faster to keep
the iterators on the stack versus enumerations where you have to put
things on the heap?

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

Reply via email to