poly.ml
open Polynome
  
(* L'anneau des flottants --c'est plus intéressant que les entiers... *) 
module F =
  struct
    type t = float
    let zéro = 0.
    let unité = 1.
    let nég x = -. x
    let plus = ( +. )
    let mult = ( *. )
    let equal = ( = )
    let string = string_of_float
  end;;
module X = Make (F) (struct let nom_variable = "X" end);;

(* construction d'un polynome: le coefficients en X^k est représenté
   par un flottant à l'indice k du tableau *)
let poly t =
  Array.fold_left
    (fun r (s, k) -> X.plus (X.monôme (float_of_string s) k) r)
    X.zéro
    (Array.mapi (fun i x -> (x, i)) t)
    ;;

(* il faut enlever le premier argument qui est le nom de la commande *)
let suffix t k = Array.sub t k (Array.length t - k);;

let main () =
  let écho, 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 écho then Printf.printf "P(%f)_=_" x;
    print_float (X.eval p x); print_newline() in
  if écho then Printf.printf "P_=_%s\n" (X.string p);
  while true do print_eval (float_of_string (read_line())) done
    ;;

try main() with End_of_file -> ();;

poly.sh
#!/bin/sh
#
#   Exécuter les commandes sous le shell ou sauver ce fichier 
#   dans poly.sh et faire sh poly.sh 

./poly 1. 2. 1. <<EOF
0.5
1.
1.5
2.
2.5.
3.
EOF