简体   繁体   中英

OCaml: Adapting recursive function

i've lost all my day in this problem. So, i have a recursive function like that:

let rec rewriteTree tree =
      rewriteElement tree c;
      List.iter rewriteTree tree.subtree in
    rewriteTree myTree

The function rewriteElement returns unit (), so i haven't problems with the function rewriteTree . But, i made changes in my code and the function rewriteElement now returns a boolean, and i need that it returns a boolean list, with all booleans of all nodes of the tree. What's the best way to do that? I've tried with List.map, but the compiler throws that the function returns (boolean list list). Thanks.

Try this:

let rec rewriteTree tree =
  rewriteElement tree c ::
    List.concat (List.map rewriteTree tree.subtree) in
rewriteTree myTree

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM