open Types;; open Basic;; let nest_from_string : string -> nest = fun (s : string) -> Nstparser.main Nstlexer.token (Lexing.from_string s);; let rec basic_from_nest : nest -> basic = fun (nst : nest) -> let rec basic_from_nestpar : nestpar -> basic = fun (nstpar : nestpar) -> let rec list_from_nestpar : nestpar -> basic list = fun (np : nestpar) -> match np with | Unary n -> [basic_from_nest n] | Binary (n1, np2) -> [basic_from_nest n1] @ (list_from_nestpar np2) in match nstpar with | Unary n -> basic_from_nest n | Binary (n1, np2) -> let bl = list_from_nestpar nstpar in Vec (new vector (List.length bl) (Array.get (Array.of_list bl))) in match nst with | Scalar s -> R s | Vector np -> basic_from_nestpar np;; let rec basic_to_neststring : basic -> string = fun (b : basic) -> match b with | N i -> string_of_int i | R f -> string_of_float f | Zero -> basic_to_neststring (N 0) | Error -> "Error" | Vec vec -> let lpar = "[" in let rpar = "]" in let comma_space = ", " in let basics = Array.init vec#size vec#nth in let strings = Array.map basic_to_neststring basics in let combine = String.concat comma_space (Array.to_list strings) in lpar ^ combine ^ rpar;;