ocaml-batteries-team / batteries-included

Batteries Included project
http://ocaml-batteries-team.github.com/batteries-included/hdoc2/
Other
519 stars 106 forks source link

Unix.walk or equivalent #490

Open c-cube opened 10 years ago

c-cube commented 10 years ago

I'm not sure whether it exists already, but an equivalent of python's os.walk would be very interesting for scripting in OCaml. I could implement it maintainers think it's useful.

gasche commented 10 years ago

Why not; there is an interesting, non-trivial logic to avoid looping endlessly in case of cyclic symbolic links. I'm not sure whether we'd want to return a sequence of directories, as Python's function does, or rather a tree (which can easily be turned into a sequence afterwards) -- I'd go for the tree interface.

c-cube commented 10 years ago

that's an interesting idea; it could even be a kind of lazy tree (similar to BatSeq) for early termination. I like it.

gasche commented 10 years ago

OCamlbuild has a directory-walking implementation, which is amusingly named "slurp". Do have a look at slurp.{ml,mli}. Couldn't we just reuse this implementation?

hcarty commented 10 years ago

This looks similar to/could be built rather simply on top of the find function in FileUtils. How much overlap do we want between these libraries? Should something be used from there?

c-cube commented 10 years ago

Indeed, it even looks more powerful thanks to the test system! Maybe a batteries-friendly interface to FileUtils would be nice, then. Something like wrapping FileUtil.find in an Enum?

Actually that's an interesting global design issue: should we make wrappers around other libraries (lwt for instance?) with optional modules, that keep batteries quite small and still integrate it nicely with the rest of the OCaml ecosystem? Opam's conditional compilation would help keeping this sane.

hcarty commented 10 years ago

This may be getting off-topic for a github bug discussion - but what is the proper approach for wrapping an external library for Batteries-friendly use? There are a few which would be nice to have in a Batteries-friendly form (Calendar, FileUtils, Lwt).

c-cube commented 10 years ago

@hcarty let's move it to the mailing list if you want. edit: done

UnixJunkie commented 8 years ago

I also need this sometimes. There is one in FileUtils however. Not sure we should have one in batteries too.