Browse thread
[Caml-list] [ANN] The Missing Library
-
John Goerzen
-
Kenneth Knowles
- Alexander V. Voinov
-
John Goerzen
-
Maxence Guesdon
-
John Goerzen
- Maxence Guesdon
-
John Goerzen
-
Alain.Frisch@e...
-
John Goerzen
-
Alain.Frisch@e...
-
Nicolas Cannasse
-
Yamagata Yoriyuki
- Gerd Stolpmann
-
Nicolas Cannasse
-
Yamagata Yoriyuki
- Jacques GARRIGUE
- Nicolas Cannasse
-
Yamagata Yoriyuki
-
Yamagata Yoriyuki
-
Nicolas Cannasse
- oliver@f...
-
Alain.Frisch@e...
-
John Goerzen
- Henri DF
- Shawn Wagner
- james woodyatt
-
Alain.Frisch@e...
- Basile STARYNKEVITCH
-
John Goerzen
- Kenneth Knowles
- Florian Hars
-
Maxence Guesdon
- Eric C. Cooper
-
Kenneth Knowles
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2004-04-28 (13:29) |
From: | Andreas Rossberg <rossberg@p...> |
Subject: | Re: [Caml-list] [ANN] The Missing Library |
skaller wrote: >> >>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. > I think the answer is 'C++ templates provide functorial > polymorphism (polyadicity), Ocaml has no such expressive power.' It has, but only on the module level. Anyway, I don't think it is needed for generic iteration. The most important aspects of iterators easily can be captures by either HOFs or by lazy streams. For example, a forward iterator just might be an arbitrary function of type unit -> 'a option Repeated calls advance the iterator, at the end it returns None. More functionally, with streams, an iterator is a value of type 'a stream, probably definable in OCaml as follows: type 'a stream = 'a stream' lazy_t and 'a stream' = Nil | Cons of 'a * 'a stream Essentially, you iterate over (parts of) arbitrary structure by turning them into lazy lists. Using laziness to move from a push to a pull model (which is what your control inversion means, IIUC) is rather a standard FP technique. The main difference wrt C++ style iterators is that you need to give the end of the iteration in advance (if you want some particular range). I don't think you lose something important by that limitation. - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de Let's get rid of those possible thingies! -- TB ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners