Advertisement
Guest User

Untitled

a guest
May 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.71 KB | None | 0 0
  1. type ntree = Leaf of string | Ntr of string * ntree list;;
  2. let ntr1 = Ntr("/", [Ntr("etc", [Leaf("fstab");Leaf("mtab")]);Leaf(".empty")]);;
  3. let find_path ntr l1 =
  4.     let rec fp' ctl lc =
  5.       match lc with
  6.           [] -> true
  7.       | x::xs ->
  8.         match ctl with
  9.           Ntr(path, nls)::ys ->
  10.             if (x = path) then
  11.                 fp' nls xs (* go down the tree then! *)
  12.             else
  13.                 fp' ys lc (* try to match at the same tree level *)
  14.         |  Leaf(path)::ys ->
  15.             if (x = path) then
  16.                 fp' ys xs (* go down the path *)
  17.             else
  18.                 fp' ys lc (* search at the same level *)
  19.         | _ -> false
  20.     in
  21.     fp' [ntr] l1;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement