Version franēaise
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] [ANN] The Missing Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-28 (13:39)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] [ANN] The Missing Library

skaller writes:
 > > > > I'm wondering what concepts Ocaml can't express/enforce? 
 > > > 
 > > > Iterators. 
 > > 
 > > Why can't you do this kind of in ocaml?  Returning something like a
 > > "next" function would seem to give you a very basic (but usable)
 > > iterator.  Which part of the iterator abstraction can't you do?
 > I suggest you try it. I don't know how to answer the question.

Perhaps I missed  something in this thread but it  is not so difficult
to  write iterators  in  ocaml (of  course it  can  not be  done in  a
systematic way --- may be that was John's point).

In ocamlgraph we provide depth-first and breadth-first graph traversal
both as HOF and as iterators. Iterators have the following signature:

  type iterator
  val start : G.t -> iterator
  val step : iterator -> iterator
  val get : iterator -> G.V.t

(where G.t is  the type of graphs).  It was a lot of  fun coding these
itearators,  and very  useful  to write  a  backtracking algorithm  to
colors graphs.  It was particularly easy as  iterators are implemented
as persistent  data structures:  thus there is  no `undo' part  in the
backtracking code.

I guess one cannot write  a backtracking algorithm using the usual HOF
fold function.

If one is interested the code is here:

Jean-Christophe Filliātre

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: