Loading ...
Sorry, an error occurred while loading the content.
 

Fatal error: exception Failure("nth")

Expand Messages
  • Kim Quyen Ly
    I had these functions computed and ordering an xsd list. val flatten : Xsd.xsd list - Xsd.xsd list val convert_xsds : Xsd.xsd list - bool array array val
    Message 1 of 10 , Jan 3, 2012
      I had these functions computed and ordering an xsd list.

      val flatten : Xsd.xsd list -> Xsd.xsd list
      val convert_xsds : Xsd.xsd list -> bool array array
      val transClosure : 'a array array -> 'a array array
      val eq_class : bool array array -> int -> int list
      val eq_classes : bool array array -> int list list
      val cmp_classes : bool array array -> int list -> int list -> int
      val sort_eq_classes : bool array array -> int list list -> int list list

      (* ordering xsds list *)
      let order_xsds xsds =
      let xsds_flatten = flatten xsds in
      let tc_xsds = transClosure (convert_xsds xsds_flatten) in
      let eq_xsds = eq_classes tc_xsds in
      let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
      sort_eq_xsds

      After I had a result of an ordering (val order_xsds : Xsd.xsd list -> int list list ) , I would like to return an element corresponding to their position. I write this function to convert

      val name_of_num : 'a list -> int -> 'a

      (* convert int list of lists to xsds list of lists *)
      let con_int_xsds xsds =
      let xsds = flatten xsds in
      let ints_of_xsds = List.map (List.map (name_of_num xsds)) in
      let sort_xsds = ints_of_xsds (order_xsds xsds) in
      sort_xsds

      The problem is that when I run this code it gives an exception Fatal error: exception Failure("nth") and I found out that it is at the function ints_of_xsds

      My question is that: I wonder is it the function ints_of_xsds a problem? or somewhere else? How can I correct it?

      Thank you very much!
    • Gabriel Scherer
      I suppose the error is in the name_of_num function, which returns an integer that is not a correct index in the list. If you have trouble knowing where an
      Message 2 of 10 , Jan 3, 2012
        I suppose the error is in the name_of_num function, which returns an
        integer that is not a correct index in the list.

        If you have trouble knowing where an exception started from, you can
        use backtraces by running OCaml programs under the environment
        OCAMLRUNPARAM="b"
        OCAMLRUNPARAM="b" ./my_program

        This works for native programs (ocamlopt) and bytecode programs
        compiled with debugging enabled (ocamlc -g ...).

        On Tue, Jan 3, 2012 at 9:41 AM, Kim Quyen Ly <lykimq@...> wrote:
        > I had these functions computed and ordering an xsd list.
        >
        > val flatten : Xsd.xsd list -> Xsd.xsd list
        > val convert_xsds : Xsd.xsd list -> bool array array
        > val transClosure : 'a array array -> 'a array array
        > val eq_class : bool array array -> int -> int list
        > val eq_classes : bool array array -> int list list
        > val cmp_classes : bool array array -> int list -> int list -> int
        > val sort_eq_classes : bool array array -> int list list -> int list list
        >
        > (* ordering xsds list *)
        > let order_xsds xsds =
        > let xsds_flatten = flatten xsds in
        > let tc_xsds = transClosure (convert_xsds xsds_flatten) in
        > let eq_xsds = eq_classes tc_xsds in
        > let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
        > sort_eq_xsds
        >
        > After I had a result of an ordering (val order_xsds : Xsd.xsd list -> int list list ) , I would like to return an element corresponding to their position. I write this function to convert
        >
        > val name_of_num : 'a list -> int -> 'a
        >
        > (* convert int list of lists to xsds list of lists *)
        > let con_int_xsds xsds =
        > let xsds = flatten xsds in
        > let ints_of_xsds = List.map (List.map (name_of_num xsds)) in
        > let sort_xsds = ints_of_xsds (order_xsds xsds) in
        > sort_xsds
        >
        > The problem is that when I run this code it gives an exception Fatal error: exception Failure("nth") and I found out that it is at the function ints_of_xsds
        >
        > My question is that: I wonder is it the function ints_of_xsds a problem? or somewhere else? How can I correct it?
        >
        > Thank you very much!
        >
        >
        >
        > ------------------------------------
        >
        > Archives up to December 31, 2010 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
        > The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
        > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
        >
        >
        >
      • Kim Quyen Ly
        I know that was a problem of function name_of_num because its length is too short compare to the list I returned (list equivalence classes). Here is an example
        Message 3 of 10 , Jan 4, 2012
          I know that was a problem of function name_of_num because its length is too short compare to the list I returned (list equivalence classes).

          Here is an example describe what I want for my test (taken from the question I asked before: http://tech.groups.yahoo.com/group/ocaml_beginners/message/13060 )

          let entries = [("name", ["string"]); ("label", ["nonNegativeInteger"; "name"])];;

          let transClosure m =
          let n = Array.length m in
          for k = 0 to n - 1 do
          let mk = m.(k) in
          for i = 0 to n - 1 do
          let mi = m.(i) in
          for j = 0 to n - 1 do
          mi.(j) <- max mi.(j) (min mi.(k) mk.(j))
          done;
          done;
          done;
          m;;

          let eq_class m i =
          let column = m.(i)
          and set = ref [] in
          Array.iteri begin fun j l ->
          if j = i || column.(j) && m.(j).(i) then
          set := j :: !set else ignore l
          end column;
          !set;;

          let eq_classes m =
          let classes = ref [] in
          Array.iteri begin fun e _ ->
          if not (List.exists (List.mem e) !classes) then
          classes := eq_class m e :: !classes
          end m;
          !classes;;

          let cmp_classes m c c' = if c = c' then 0 else
          match c, c' with
          | i :: _, j :: _ -> if m.(i).(j) then 1 else -1
          | _ -> assert false

          let sort_eq_classes m = List.sort (cmp_classes m);;

          let rec position x = function
          | [] -> raise Not_found
          | y :: ys -> if x = y then 0 else 1 + position x ys

          let flatten_entry (str,strs) = str::strs

          let strings = uniqify (List.flatten (List.map flatten_entry entries))

          let convert =
          let num_strings = List.length strings in
          let boolmat = Array.make_matrix num_strings num_strings false in
          let posn str = position str strings in
          let set_pair str1 str2 =
          boolmat.(posn str1).(posn str2) <- true in
          let set_entry (str, strs) = List.iter (set_pair str) strs in
          let set_all () = List.iter set_entry entries in
          set_all();
          boolmat;;

          let tc = transClosure convert

          let eq = eq_classes tc

          let sort = sort_eq_classes tc eq

          let name_xsds = List.map (List.map (List.nth strings)) sort;;

          output:
          list equivalence classes ('sort' function) is: [[3]; [1; 0; 2]]
          'name_xsds' I can return their element corresponding to the list of equivalence classes: nonNegativeInteger string name label

          When I test with xsd trees, I used the same method as my counter example.

          let strings_xsds xsds =
          uniquify (List.flatten (List.map flatten_entry (get_list_xsds xsds))) --> it is exactly does the same as 'strings' function in the example above, where get_list_xsds : Xsd.xsd list -> (string * string list) list

          let order_xsds xsds =
          let tc_xsds = transClosure (convert_xsds xsds) in
          let eq_xsds = eq_classes tc_xsds in
          let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
          let return = List.map (List.map (List.nth (strings_xsds xsds)))
          sort_eq_xsds in
          return

          it returned for me an string list of lists, but when I run the program, it doesn't terminate. Also the function I support generate taking an xsd list of lists as an argument. So I would like to convert it to xsds list of lists instead of string list of lists.

          Could you help me to see this problem clearer? How can I mapping an int list of lists to an xsd list of lists?

          I am sorry my question too long!!

          Thanks

          --- In ocaml_beginners@yahoogroups.com, "Kim Quyen Ly" <lykimq@...> wrote:
          >
          > I had these functions computed and ordering an xsd list.
          >
          > val flatten : Xsd.xsd list -> Xsd.xsd list
          > val convert_xsds : Xsd.xsd list -> bool array array
          > val transClosure : 'a array array -> 'a array array
          > val eq_class : bool array array -> int -> int list
          > val eq_classes : bool array array -> int list list
          > val cmp_classes : bool array array -> int list -> int list -> int
          > val sort_eq_classes : bool array array -> int list list -> int list list
          >
          > (* ordering xsds list *)
          > let order_xsds xsds =
          > let xsds_flatten = flatten xsds in
          > let tc_xsds = transClosure (convert_xsds xsds_flatten) in
          > let eq_xsds = eq_classes tc_xsds in
          > let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
          > sort_eq_xsds
          >
          > After I had a result of an ordering (val order_xsds : Xsd.xsd list -> int list list ) , I would like to return an element corresponding to their position. I write this function to convert
          >
          > val name_of_num : 'a list -> int -> 'a
          >
          > (* convert int list of lists to xsds list of lists *)
          > let con_int_xsds xsds =
          > let xsds = flatten xsds in
          > let ints_of_xsds = List.map (List.map (name_of_num xsds)) in
          > let sort_xsds = ints_of_xsds (order_xsds xsds) in
          > sort_xsds
          >
          > The problem is that when I run this code it gives an exception Fatal error: exception Failure("nth") and I found out that it is at the function ints_of_xsds
          >
          > My question is that: I wonder is it the function ints_of_xsds a problem? or somewhere else? How can I correct it?
          >
          > Thank you very much!
          >
        • Gabriel Scherer
          I still don t see the code for name_of_num . Could you post a self-contained OCaml code (that is, that can be compiled and executed as is) that exhibits your
          Message 4 of 10 , Jan 4, 2012
            I still don't see the code for "name_of_num". Could you post a
            self-contained OCaml code (that is, that can be compiled and executed
            as is) that exhibits your problem (raises the exception)?

            On Wed, Jan 4, 2012 at 12:10 PM, Kim Quyen Ly <lykimq@...> wrote:
            > I know that was a problem of function name_of_num because its length is too short compare to the list I returned (list equivalence classes).
            >
            > Here is an example describe what I want for my test (taken from the question I asked before: http://tech.groups.yahoo.com/group/ocaml_beginners/message/13060 )
            >
            > let entries = [("name", ["string"]); ("label", ["nonNegativeInteger"; "name"])];;
            >
            > let transClosure m =
            >  let n = Array.length m in
            >  for k = 0 to n - 1 do
            >    let mk = m.(k) in
            >    for i = 0 to n - 1 do
            >      let mi = m.(i) in
            >      for j = 0 to n - 1 do
            >        mi.(j) <- max mi.(j) (min mi.(k) mk.(j))
            >      done;
            >    done;
            >  done;
            >  m;;
            >
            > let eq_class m i =
            >  let column = m.(i)
            >  and set = ref [] in
            >  Array.iteri begin fun j l ->
            >    if j = i || column.(j) && m.(j).(i) then
            >      set := j :: !set else ignore l
            >  end column;
            >  !set;;
            >
            > let eq_classes m =
            >  let classes = ref [] in
            >  Array.iteri begin fun e _ ->
            >    if not (List.exists (List.mem e) !classes) then
            >      classes := eq_class m e :: !classes
            >  end m;
            >  !classes;;
            >
            > let cmp_classes m c c' = if c = c' then 0 else
            >  match c, c' with
            >    | i :: _, j :: _ -> if m.(i).(j) then 1 else -1
            >    | _ -> assert false
            >
            > let sort_eq_classes m = List.sort (cmp_classes m);;
            >
            > let rec position x = function
            > | [] -> raise Not_found
            > | y :: ys -> if x = y then 0 else 1 + position x ys
            >
            > let flatten_entry (str,strs) = str::strs
            >
            > let strings = uniqify (List.flatten (List.map flatten_entry entries))
            >
            > let convert =
            >  let num_strings = List.length strings in
            >  let boolmat = Array.make_matrix num_strings num_strings false in
            >  let posn str = position str strings in
            >  let set_pair str1 str2 =
            >    boolmat.(posn str1).(posn str2) <- true in
            >  let set_entry (str, strs) = List.iter (set_pair str) strs in
            >  let set_all () = List.iter set_entry entries in
            >  set_all();
            >  boolmat;;
            >
            > let tc = transClosure convert
            >
            > let eq = eq_classes tc
            >
            > let sort = sort_eq_classes tc eq
            >
            > let name_xsds = List.map (List.map (List.nth strings)) sort;;
            >
            > output:
            > list equivalence classes ('sort' function) is: [[3]; [1; 0; 2]]
            > 'name_xsds' I can return their element corresponding to the list of equivalence classes:  nonNegativeInteger string name  label
            >
            > When I test with xsd trees, I used the same method as my counter example.
            >
            > let strings_xsds xsds =
            >  uniquify (List.flatten (List.map flatten_entry (get_list_xsds xsds))) --> it is exactly does the same as 'strings' function in the example above, where get_list_xsds : Xsd.xsd list -> (string * string list) list
            >
            > let order_xsds xsds =
            >  let tc_xsds = transClosure (convert_xsds xsds) in
            >  let eq_xsds = eq_classes tc_xsds in
            >  let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
            >  let return = List.map (List.map (List.nth (strings_xsds xsds)))
            >    sort_eq_xsds in
            >  return
            >
            > it returned for me an string list of lists, but when I run the program, it doesn't terminate. Also the function I support generate taking an xsd list of lists as an argument. So I would like to convert it to xsds list of lists instead of string list of lists.
            >
            > Could you help me to see this problem clearer? How can I mapping an int list of lists to an xsd list of lists?
            >
            > I am sorry my question too long!!
            >
            > Thanks
            >
            > --- In ocaml_beginners@yahoogroups.com, "Kim Quyen Ly" <lykimq@...> wrote:
            >>
            >> I had these functions computed and ordering an xsd list.
            >>
            >> val flatten : Xsd.xsd list -> Xsd.xsd list
            >> val convert_xsds : Xsd.xsd list -> bool array array
            >> val transClosure : 'a array array -> 'a array array
            >> val eq_class : bool array array -> int -> int list
            >> val eq_classes : bool array array -> int list list
            >> val cmp_classes : bool array array -> int list -> int list -> int
            >> val sort_eq_classes : bool array array -> int list list -> int list list
            >>
            >> (* ordering xsds list *)
            >> let order_xsds xsds =
            >> let xsds_flatten = flatten xsds in
            >> let tc_xsds = transClosure (convert_xsds xsds_flatten) in
            >> let eq_xsds = eq_classes tc_xsds in
            >> let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
            >> sort_eq_xsds
            >>
            >> After I had a result of an ordering (val order_xsds : Xsd.xsd list -> int list list ) , I would like to return an element corresponding to their position. I write this function to convert
            >>
            >> val name_of_num : 'a list -> int -> 'a
            >>
            >> (* convert int list of lists to xsds list of lists *)
            >> let con_int_xsds xsds =
            >> let xsds = flatten xsds in
            >> let ints_of_xsds = List.map (List.map (name_of_num xsds)) in
            >> let sort_xsds = ints_of_xsds (order_xsds xsds) in
            >> sort_xsds
            >>
            >> The problem is that when I run this code it gives an exception Fatal error: exception Failure("nth") and I found out that it is at the function ints_of_xsds
            >>
            >> My question is that: I wonder is it the function ints_of_xsds a problem? or somewhere else? How can I correct it?
            >>
            >> Thank you very much!
            >>
            >
            >
            >
            >
            > ------------------------------------
            >
            > Archives up to December 31, 2010 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
            > The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
            > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
            >
            >
            >
          • Kim Quyen Ly
            let name_of_num (l: a list) (i: int) : a = List.nth l i;;
            Message 5 of 10 , Jan 4, 2012
              let name_of_num (l: 'a list) (i: int) : 'a = List.nth l i;;


              --- In ocaml_beginners@yahoogroups.com, Gabriel Scherer <gabriel.scherer@...> wrote:
              >
              > I still don't see the code for "name_of_num". Could you post a
              > self-contained OCaml code (that is, that can be compiled and executed
              > as is) that exhibits your problem (raises the exception)?
              >
              > On Wed, Jan 4, 2012 at 12:10 PM, Kim Quyen Ly <lykimq@...> wrote:
              > > I know that was a problem of function name_of_num because its length is too short compare to the list I returned (list equivalence classes).
              > >
              > > Here is an example describe what I want for my test (taken from the question I asked before: http://tech.groups.yahoo.com/group/ocaml_beginners/message/13060 )
              > >
              > > let entries = [("name", ["string"]); ("label", ["nonNegativeInteger"; "name"])];;
              > >
              > > let transClosure m =
              > >  let n = Array.length m in
              > >  for k = 0 to n - 1 do
              > >    let mk = m.(k) in
              > >    for i = 0 to n - 1 do
              > >      let mi = m.(i) in
              > >      for j = 0 to n - 1 do
              > >        mi.(j) <- max mi.(j) (min mi.(k) mk.(j))
              > >      done;
              > >    done;
              > >  done;
              > >  m;;
              > >
              > > let eq_class m i =
              > >  let column = m.(i)
              > >  and set = ref [] in
              > >  Array.iteri begin fun j l ->
              > >    if j = i || column.(j) && m.(j).(i) then
              > >      set := j :: !set else ignore l
              > >  end column;
              > >  !set;;
              > >
              > > let eq_classes m =
              > >  let classes = ref [] in
              > >  Array.iteri begin fun e _ ->
              > >    if not (List.exists (List.mem e) !classes) then
              > >      classes := eq_class m e :: !classes
              > >  end m;
              > >  !classes;;
              > >
              > > let cmp_classes m c c' = if c = c' then 0 else
              > >  match c, c' with
              > >    | i :: _, j :: _ -> if m.(i).(j) then 1 else -1
              > >    | _ -> assert false
              > >
              > > let sort_eq_classes m = List.sort (cmp_classes m);;
              > >
              > > let rec position x = function
              > > | [] -> raise Not_found
              > > | y :: ys -> if x = y then 0 else 1 + position x ys
              > >
              > > let flatten_entry (str,strs) = str::strs
              > >
              > > let strings = uniqify (List.flatten (List.map flatten_entry entries))
              > >
              > > let convert =
              > >  let num_strings = List.length strings in
              > >  let boolmat = Array.make_matrix num_strings num_strings false in
              > >  let posn str = position str strings in
              > >  let set_pair str1 str2 =
              > >    boolmat.(posn str1).(posn str2) <- true in
              > >  let set_entry (str, strs) = List.iter (set_pair str) strs in
              > >  let set_all () = List.iter set_entry entries in
              > >  set_all();
              > >  boolmat;;
              > >
              > > let tc = transClosure convert
              > >
              > > let eq = eq_classes tc
              > >
              > > let sort = sort_eq_classes tc eq
              > >
              > > let name_xsds = List.map (List.map (List.nth strings)) sort;;
              > >
              > > output:
              > > list equivalence classes ('sort' function) is: [[3]; [1; 0; 2]]
              > > 'name_xsds' I can return their element corresponding to the list of equivalence classes:  nonNegativeInteger string name  label
              > >
              > > When I test with xsd trees, I used the same method as my counter example.
              > >
              > > let strings_xsds xsds =
              > >  uniquify (List.flatten (List.map flatten_entry (get_list_xsds xsds))) --> it is exactly does the same as 'strings' function in the example above, where get_list_xsds : Xsd.xsd list -> (string * string list) list
              > >
              > > let order_xsds xsds =
              > >  let tc_xsds = transClosure (convert_xsds xsds) in
              > >  let eq_xsds = eq_classes tc_xsds in
              > >  let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
              > >  let return = List.map (List.map (List.nth (strings_xsds xsds)))
              > >    sort_eq_xsds in
              > >  return
              > >
              > > it returned for me an string list of lists, but when I run the program, it doesn't terminate. Also the function I support generate taking an xsd list of lists as an argument. So I would like to convert it to xsds list of lists instead of string list of lists.
              > >
              > > Could you help me to see this problem clearer? How can I mapping an int list of lists to an xsd list of lists?
              > >
              > > I am sorry my question too long!!
              > >
              > > Thanks
              > >
              > > --- In ocaml_beginners@yahoogroups.com, "Kim Quyen Ly" <lykimq@> wrote:
              > >>
              > >> I had these functions computed and ordering an xsd list.
              > >>
              > >> val flatten : Xsd.xsd list -> Xsd.xsd list
              > >> val convert_xsds : Xsd.xsd list -> bool array array
              > >> val transClosure : 'a array array -> 'a array array
              > >> val eq_class : bool array array -> int -> int list
              > >> val eq_classes : bool array array -> int list list
              > >> val cmp_classes : bool array array -> int list -> int list -> int
              > >> val sort_eq_classes : bool array array -> int list list -> int list list
              > >>
              > >> (* ordering xsds list *)
              > >> let order_xsds xsds =
              > >> let xsds_flatten = flatten xsds in
              > >> let tc_xsds = transClosure (convert_xsds xsds_flatten) in
              > >> let eq_xsds = eq_classes tc_xsds in
              > >> let sort_eq_xsds = sort_eq_classes tc_xsds eq_xsds in
              > >> sort_eq_xsds
              > >>
              > >> After I had a result of an ordering (val order_xsds : Xsd.xsd list -> int list list ) , I would like to return an element corresponding to their position. I write this function to convert
              > >>
              > >> val name_of_num : 'a list -> int -> 'a
              > >>
              > >> (* convert int list of lists to xsds list of lists *)
              > >> let con_int_xsds xsds =
              > >> let xsds = flatten xsds in
              > >> let ints_of_xsds = List.map (List.map (name_of_num xsds)) in
              > >> let sort_xsds = ints_of_xsds (order_xsds xsds) in
              > >> sort_xsds
              > >>
              > >> The problem is that when I run this code it gives an exception Fatal error: exception Failure("nth") and I found out that it is at the function ints_of_xsds
              > >>
              > >> My question is that: I wonder is it the function ints_of_xsds a problem? or somewhere else? How can I correct it?
              > >>
              > >> Thank you very much!
              > >>
              > >
              > >
              > >
              > >
              > > ------------------------------------
              > >
              > > Archives up to December 31, 2010 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
              > > The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
              > > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
              > >
              > >
              > >
              >
            • Dan Bensen
              ... Quyen, I think Gabriel is asking you to post a complete program. That would be much easier to analyze. ... [Non-text portions of this message have been
              Message 6 of 10 , Jan 4, 2012
                > let name_of_num (l: 'a list) (i: int) : 'a = List.nth l i;;

                Quyen, I think Gabriel is asking you to post a complete program.
                That would be much easier to analyze.

                > Could you post a self-contained OCaml code
                > (that is, that can be compiled and executed as is)

                > that exhibits your problem (raises the exception)?

                [Non-text portions of this message have been removed]
              • Kim Quyen Ly
                Thanks!! I was trying to post all the code, but it was a group of files. I try to describe it. Here is a part of xsd trees, from this tree I parse into a list
                Message 7 of 10 , Jan 4, 2012
                  Thanks!! I was trying to post all the code, but it was a group of files.

                  I try to describe it. Here is a part of xsd trees, from this tree I parse into a list and split this xsds list into a pair (string * string list) list, for example:

                  [("name", ["string"]); ("label", ["nonNegativeInteger"; "name"])]

                  after computed and ordered this list (used the functions I posted before), it returned for me an int list of lists (for example: [[3]; [2; 1; 0]]).

                  The problem is that the list of ordered is included their type (here is: string, nonNegativeInteger, and name; their length is 4), but the list of xsds they don't (for example: the length of this xsds list is 1), so that why it raise an exception Failure ("nth")

                  <xs:element name="name" type="xs:string"> </xs:element>
                  <xs:group name="label">
                  <xs:choice>
                  <xs:element name="numberLabel">
                  <xs:complexType>
                  <xs:sequence>
                  <xs:element maxOccurs="unbounded" minOccurs="0" name="number" type="xs:nonNegativeInteger"/>
                  </xs:sequence>
                  </xs:complexType>
                  </xs:element>
                  <xs:element name="symbolLabel">
                  <xs:complexType>
                  <xs:sequence>
                  <xs:group maxOccurs="unbounded" minOccurs="0" ref="name"/>
                  </xs:sequence>
                  </xs:complexType>
                  </xs:element>
                  </xs:choice>
                  </xs:group>

                  Here is a generate function that generate each type and print type and their depends type.

                  val genr_type : Buffer.t -> Xsd.xsd -> unit

                  let print_types b xsds =
                  List.iter (function
                  | [] -> assert false
                  | h :: t -> bprintf b "%a" genr_type h;
                  List.iter (fun xsd -> bprintf b "\n\n%a" genr_type xsd) t)
                  xsds;;

                  let genr_types b xsds = print_types b xsds;;

                  and I want to keep the relation depends of their dependence, because I support to print the type in Coq format, for example:

                  Definition name := string.

                  Inductive label :=
                  | Label_numberLabel : list nonNegativeInteger -> label
                  | Label_symbolLabel : list name -> label.

                  so I want after ordered, it returned for me a list of their positions, for example it returned for me [[3]; [2; 1; 0]] --> nonNegative (3), label (2), string (1), name (0), but keep the type depends. For example, 'name' depends on 'string' so it should keep their order: name string; 'label' depends on 'name' so 'name' will print before 'label'.
                  I am trying my best to explain but it is what I understand right now.




                  --- In ocaml_beginners@yahoogroups.com, Dan Bensen <danbensen@...> wrote:
                  >
                  > > let name_of_num (l: 'a list) (i: int) : 'a = List.nth l i;;
                  >
                  > Quyen, I think Gabriel is asking you to post a complete program.
                  > That would be much easier to analyze.
                  >
                  > > Could you post a self-contained OCaml code
                  > > (that is, that can be compiled and executed as is)
                  >
                  > > that exhibits your problem (raises the exception)?
                  >
                  > [Non-text portions of this message have been removed]
                  >
                • Dan Bensen
                  ... So the list of names is [ name ; string ; label ; nonNegativeInteger ] ... How does string depend on name or label ? ... You already have the
                  Message 8 of 10 , Jan 4, 2012
                    > nonNegative (3), label (2), string (1), name (0)

                    So the list of names is ["name";"string";"label";"nonNegativeInteger"]

                    > [[3]; [2; 1; 0]]

                    How does "string" depend on "name" or "label"?

                    > keep the type depends

                    You already have the dependencies in the pair list:
                    [("name", ["string"]); ("label", ["nonNegativeInteger"; "name"])]

                    What more do you need?


                    [Non-text portions of this message have been removed]
                  • Dan Bensen
                    ... Well, I don t know what those numbers in the other posts are supposed to mean, but (m.(i).(j) && m.(j).(i)) seems to be looking for mutually dependent
                    Message 9 of 10 , Jan 4, 2012
                      > let eq_class m i =
                      > let column = m.(i)
                      > ...
                      > if j = i || column.(j) && m.(j).(i) then
                      > ...

                      Well, I don't know what those numbers in the other posts are supposed to mean,
                      but (m.(i).(j) && m.(j).(i)) seems to be looking for mutually dependent terms,
                      so here's some code that does that. With "label" added to the dependencies of
                      "name", the result is

                      [["name"; "label"]; ["string"]; ["integer"]]

                      open List

                      let rec uniqify = function
                      | [] -> []
                      | x::xs -> x :: uniqify (filter ((<>) x) xs)

                      let entries = [("name", ["label";"string"]); ("label", ["integer"; "name"])]

                      let flatten_entry (str,strs) = str::strs

                      let uniq_flat_map f xs = uniqify (flatten (map f xs))

                      let all_words = uniq_flat_map flatten_entry entries

                      let find_entry x entries = find (fun (y,_) -> y = x) entries

                      let entry_of x = try find_entry x entries with Not_found -> (x,[])

                      let all_entries = map entry_of all_words

                      let deps x = snd (find_entry x all_entries)

                      let has_dep x y = mem y (deps x)

                      let rec slow_partition eq_xs = function
                      | [] -> (eq_xs,[])
                      | other_xs ->
                      let new_deps = uniq_flat_map deps eq_xs in
                      let is_codep y = (not (mem y eq_xs)) && exists (has_dep y) eq_xs in
                      let codeps = filter is_codep new_deps in
                      if codeps = [] then (eq_xs,other_xs)
                      else
                      let remainder = filter (fun x -> not (mem x codeps)) other_xs in
                      slow_partition (eq_xs @ codeps) remainder

                      let rec eq_classes = function
                      | [] -> []
                      | x::xs ->
                      let (eq_class,remainder) = slow_partition [x] xs in
                      eq_class :: eq_classes remainder

                      let all_eq_classes = eq_classes all_words

                      [Non-text portions of this message have been removed]
                    • Kim Quyen Ly
                      Hi, Thank you for your answers!! After that I see my problem was not that. Here is my question. From this list example: let entries = [( symbol ,
                      Message 10 of 10 , Jan 5, 2012
                        Hi,
                        Thank you for your answers!! After that I see my problem was not that.

                        Here is my question. From this list example:

                        let entries = [("symbol", ["label";"string"]); ("label", ["integer"; "name"]); ("name", ["string"])]

                        The result I print into Coq format was:

                        Inductive symbol =
                        | Name_label : label -> name
                        | Name_string : string -> name.

                        Inductive label =
                        | Label_Int : integer -> label
                        | Label_name : name -> label.

                        Inductive name =
                        | Name : string -> name.

                        What I was trying to do is finding an equivalence class (symbol, label) and single class and order like this result:

                        Definition name = string.

                        Inductive symbol =
                        | Name_label : label -> name
                        | Name_string : string -> name

                        with label =
                        | Label_Int : integer -> label
                        | Label_name : name -> label.

                        So when it is a same class they will print 'Inductive - with' (when it is Choice constructor in xsds), if they are not they will print 'Definition' (when it is SimpleType and Sequence in xsds structure) .

                        What I don't understand and confuse is after I found the equivalence classes, I don't know how to apply them to make them print for me what I want.

                        Here is code I used to print:

                        let todo b = string b "todo";;

                        Where type_def just print an properties type.

                        val type_def : string -> Buffer.t -> Xsd.xsd -> unit

                        let genr_type b = function
                        | Elt (n, Some t, _, _) | Group (n, Some t, _, _) ->
                        begin match t with
                        | SimpleType tn ->
                        (*it should print Definition*)
                        bprintf b "%s := \n| %s : %a -> %s" n
                        (String.capitalize n) (type_def n) t n
                        | Sequence _xs ->
                        (* it should print Definition *)
                        bprintf b "%s := \n| %s : %a -> %s" n
                        (String.capitalize n) (type_def n) t n
                        | Choice _xs ->
                        (*it should print Inductive - with if it in a same class*)
                        bprintf b "%s := %a" n (type_def n) t
                        | _ -> assert false
                        end
                        | Elt _ | Group _ | SimpleType _ | GroupRef _ | Choice _ | Sequence _ -> todo b;;


                        let init_types, is_group, next_type, add_type =
                        let types = ref [] (* list of types to be generated *)
                        and generated_types = ref [] (* list of generated types *)
                        and groups = ref StrSet.empty (* set of groups *) in

                        let counter () = let k = ref 0 in fun () -> incr k; !k;;

                        (* init_types: reset list of generated types and compute the set of groups from a list of xsd values *)
                        (let add_group = function
                        | Group (n, _, _, _) -> groups := StrSet.add n !groups
                        | Elt _ | GroupRef _ | Choice _ | Sequence _ | SimpleType _ -> ()
                        in fun xs -> types := xs; List.iter add_group xs),

                        (* is_group: say if a name is a group name *)
                        (fun n -> StrSet.mem n !groups),

                        (* next_type: return to the next type to generate and add it to the list of generated types if it exists, or raise Not_found *)
                        (fun () -> match !types with
                        | [] -> raise Not_found
                        | t :: ts -> types := ts; generated_types := t :: !generated_types; t),

                        (* add_type: add a type to the list of types to be generated
                        if it is a new type (not already in types or generated_types);
                        generate a new name if no name is given *)
                        (let new_type_id = counter() (* counter for new types *) in
                        let new_type_name () = Printf.sprintf "t%d" (new_type_id())
                        and add_group n x =
                        types := Group (n, Some x, 1, Bound 1) :: !types; (n, true)
                        in fun no x ->
                        match no with
                        | Some n -> let n = keywords n in
                        begin match List.filter (name_eq n) (!generated_types @ !types) with
                        | [] -> add_group n x
                        | [Group (_, Some y, _, _)] ->
                        if x = y then (n, false)
                        else add_group (n ^ "_" ^ new_type_name()) x
                        | _ -> assert false end
                        | None -> add_group (new_type_name()) x);;

                        let rec genr_and_types b =
                        try bprintf b "\n\nwith %a" genr_type (next_type()); genr_and_types b with Not_found -> ();;

                        let genr_types b xsds =
                        init_types xsds;
                        try bprintf b "Inductive %a" genr_type (next_type()); genr_and_types b with Not_found -> ();;


                        --- In ocaml_beginners@yahoogroups.com, Dan Bensen <danbensen@...> wrote:
                        >
                        > > let eq_class m i =
                        > > let column = m.(i)
                        > > ...
                        > > if j = i || column.(j) && m.(j).(i) then
                        > > ...
                        >
                        > Well, I don't know what those numbers in the other posts are supposed to mean,
                        > but (m.(i).(j) && m.(j).(i)) seems to be looking for mutually dependent terms,
                        > so here's some code that does that. With "label" added to the dependencies of
                        > "name", the result is
                        >
                        > [["name"; "label"]; ["string"]; ["integer"]]
                        >
                        > open List
                        >
                        > let rec uniqify = function
                        > | [] -> []
                        > | x::xs -> x :: uniqify (filter ((<>) x) xs)
                        >
                        > let entries = [("name", ["label";"string"]); ("label", ["integer"; "name"])]
                        >
                        > let flatten_entry (str,strs) = str::strs
                        >
                        > let uniq_flat_map f xs = uniqify (flatten (map f xs))
                        >
                        > let all_words = uniq_flat_map flatten_entry entries
                        >
                        > let find_entry x entries = find (fun (y,_) -> y = x) entries
                        >
                        > let entry_of x = try find_entry x entries with Not_found -> (x,[])
                        >
                        > let all_entries = map entry_of all_words
                        >
                        > let deps x = snd (find_entry x all_entries)
                        >
                        > let has_dep x y = mem y (deps x)
                        >
                        > let rec slow_partition eq_xs = function
                        > | [] -> (eq_xs,[])
                        > | other_xs ->
                        > let new_deps = uniq_flat_map deps eq_xs in
                        > let is_codep y = (not (mem y eq_xs)) && exists (has_dep y) eq_xs in
                        > let codeps = filter is_codep new_deps in
                        > if codeps = [] then (eq_xs,other_xs)
                        > else
                        > let remainder = filter (fun x -> not (mem x codeps)) other_xs in
                        > slow_partition (eq_xs @ codeps) remainder
                        >
                        > let rec eq_classes = function
                        > | [] -> []
                        > | x::xs ->
                        > let (eq_class,remainder) = slow_partition [x] xs in
                        > eq_class :: eq_classes remainder
                        >
                        > let all_eq_classes = eq_classes all_words
                        >
                        > [Non-text portions of this message have been removed]
                        >
                      Your message has been successfully submitted and would be delivered to recipients shortly.