open Polynomial module I = struct type t = int let zero = 0 let unit = 1 let plus = ( + ) let mult = ( * ) let equal = ( = ) let print = print_int end;; module Xi = Make (I);; let poly t = Array.fold_left (fun r (s, k) -> Xi.plus (Xi.monomial (int_of_string s) k) r) Xi.zero (Array.mapi (fun i x -> (x, i)) t) ;; let suffix t k = Array.sub t k (Array.length t - k);; let main () = let echo, k = if Array.length Sys.argv > 1 && Sys.argv.(1) = "-v" then true, 2 else false, 1 in let t = suffix Sys.argv k in let p = poly t in let print_eval x = if echo then Printf.printf "P(%d) = " x; print_int (Xi.eval p x); print_newline() in if echo then (print_string "P = "; Xi.print p; print_newline()); while true do print_eval (int_of_string (read_line())) done ;; try main() with End_of_file -> ();;
     
% ocamlc -o poly polynomial.mli polynomial.ml poly.ml ./poly 1 2 1 << END 0 1 2 3 END