Skip to content
Extraits de code Groupes Projets
Valider a4085165 rédigé par Edouard Paris's avatar Edouard Paris
Parcourir les fichiers

Abstract Polynome with functors

parent 2cb46c86
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
all: all:
ocamlc -c polynome.ml ocamlc -c polynome.ml
ocamlc -c simplepolynome.ml
ocamlc -c main.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: clean:
rm -f *.cm[iox] *~ .*~ #*# rm -f *.cm[iox] *~ .*~ #*#
rm -f bin/main rm -f bin/main
...@@ -2,6 +2,20 @@ ...@@ -2,6 +2,20 @@
open Big_int;; 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 = module type Polynomes =
sig sig
type polynome type polynome
...@@ -9,14 +23,14 @@ module type Polynomes = ...@@ -9,14 +23,14 @@ module type Polynomes =
end end
;; ;;
module Polynome : Polynomes = module Polynome (C : Coefficient) (D : Degree) =
struct struct
type polynome = type polynome =
|Null |Null
|NotNull of big_int*int*polynome |NotNull of C.coeff*D.degree*polynome
let rec print_pol p = match p with let rec print_pol p = match p with
|Null -> "0" |Null -> "0"
|NotNull (coeff, degree, polynome)-> |NotNull (cc, dd, pp)->
(string_of_big_int coeff)^"X^"^(string_of_int degree)^"+"^(print_pol polynome) (C.print_coeff cc)^"X^"^(D.print_degree dd)^"+"^(print_pol pp)
end end
;; ;;
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter