From a408516576f7a6b652ddc5c8ecf503f7d471f5dc Mon Sep 17 00:00:00 2001
From: Edouard Paris <mail@edouard.paris>
Date: Wed, 11 May 2016 11:24:54 +0200
Subject: [PATCH] Abstract Polynome with functors

---
 Makefile    |  3 ++-
 polynome.ml | 22 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index c36511e..f48467d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
 all:
 	ocamlc -c polynome.ml 
+	ocamlc -c simplepolynome.ml 
 	ocamlc -c main.ml 
-	ocamlc -o bin/main nums.cma polynome.cmo main.cmo
+	ocamlc -o bin/main nums.cma polynome.cmo simplepolynome.cmo main.cmo
 clean:
 	rm -f *.cm[iox] *~ .*~ #*#
 	rm -f bin/main
diff --git a/polynome.ml b/polynome.ml
index d547bb6..d4d47eb 100644
--- a/polynome.ml
+++ b/polynome.ml
@@ -2,6 +2,20 @@
 
 open Big_int;;
 
+module type Coefficient =
+  sig
+    type coeff
+    val print_coeff: coeff -> string
+  end
+;;
+  
+module type Degree =
+  sig
+    type degree
+    val print_degree: degree -> string
+  end
+;;
+  
 module type Polynomes =
   sig
     type polynome
@@ -9,14 +23,14 @@ module type Polynomes =
   end
 ;;
 
-module Polynome : Polynomes =
+module Polynome (C : Coefficient) (D : Degree) =
   struct
     type polynome =
       |Null
-      |NotNull of big_int*int*polynome
+      |NotNull of C.coeff*D.degree*polynome
     let rec print_pol p = match p with
       |Null -> "0"
-      |NotNull (coeff, degree, polynome)->
-	(string_of_big_int coeff)^"X^"^(string_of_int degree)^"+"^(print_pol polynome)
+      |NotNull (cc, dd, pp)->
+	(C.print_coeff cc)^"X^"^(D.print_degree dd)^"+"^(print_pol pp)
   end
 ;;
-- 
GitLab