Stream expression and compile
"Manfred Lotz [email protected] [ocaml_beginners]" <[email protected]> Sun, 3 Jul 2016 19:42:42 +0200
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
From https://ocaml.org/learn/tutorials/stream_expressions.html I
created a file walk.ml containing the following:
let rec walk dir =
let items =
try
Array.map
(fun fn ->
let path = Filename.concat dir fn in
try
if Sys.is_directory path then `Dir path
else `File path
with e -> `Error (path, e))
(Sys.readdir dir)
with e -> [| `Error (dir, e) |] in
Array.fold_right
(fun item rest ->
match item with
| `Dir path -> [< 'item; walk path; rest >]
| _ -> [< 'item; rest >])
items
[< >];;
let () =
Stream.iter
(function
| `Dir path -> Printf.printf "dir: %s%!\n" path
| `File path -> Printf.printf "file: %s%!\n" path
| `Error (path, e) ->
Printf.printf "error: %s (%s)%!\n" path
(Printexc.to_string e))
(walk "/tmp");;
Running this in utop works fine when I did
#use "topfind";;
#camlp4o;;
before.
However, I have no idea how to create a bytecode or native executable
from above code.
If this is dead simple I would like to get a pointer to the
documentation so that I learn what I missed to read.
Any help appreciated. Thanks.
--
Manfred