(************************************************************ dfs.ml Created : Fri Feb 7 03:34:46 2003 Last modified: Fri Feb 07 03:56:45 2003 Compile: ocamlopt.opt dfs.ml -o dfs # FTP Directory: sources/ocaml # ************************************************************) (** @author Takashi Masuyama *) type tree = Tree of string * tree list | Leaf let sample = Tree("hoge", [Tree("moge", [Leaf]); Leaf; Tree("tak", [Leaf; Leaf])]) let rec dfs n result = match n with Leaf -> result | Tree (s, lst) -> s::(List.fold_right dfs lst result) let _ = List.map print_endline (dfs sample [])