j'ai une erreur de syntaxe : faites compiler le code .Prière de m'aider à corriger .

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

type age = Bebe |Enfant | Adulte;;
(*type sexe *)
type sexe = Feminin | Masculin ;;
type pos= int*int;;

let random_age () = let rand_age= Random.int(3) in
  if(rand_age=0) then Bebe 
    else if(rand_age=1) then Enfant 
  else Adulte;;
 
 

let random_sexe () = let rand_sexe= Random.int(2) in 
  if(rand_sexe=0) then  Masculin else Feminin;;                                    

 
let string_of_age age  = match age with
 |Bebe-> "Bebe"
 |Enfant-> "Enfant"
 |Adulte-> "Adulte"
;;

let string_of_sexe sex = match sex with   
 |Feminin-> "Feminin"
 |Masculin ->"Masculin ";;


(*************************************************************)
(*signatures    (*question 6.1*)                             *)
(*************************************************************)


module type PLANETE= 
sig

  type pos 
  val ouest: pos ->pos
  val est:   pos -> pos
  val nord:  pos -> pos
  val sud : pos -> pos
  val random_pos:unit ->pos
  val at_pos : ('a-> pos)-> pos -> 'a list ->'a list
  val sort_by_pos : ('a->pos)-> 'a list ->'a list list
  val display: (int-> int-> unit)->pos->unit 
  val clear: unit->unit 
  val affiche_pos : int*int -> unit (* (a*b) -> unit *)
  val affiche_age : age -> string      

end;;



(**************************************************************)
(* Module : question 6.2         10                              *)
(**************************************************************) 
(* je considère que le tore est defini ici comme une matrice 10*10 *)

module Symbioz: PLANETE=
struct
        type pos = int*int;;(* la position couple x y *) 
 
        (* Fonction qui renvoie une position aleatoire*)
        let random_pos () = let i =Random.int(10) and j= Random.int(10) in 
                                 print_string "vous êtes à la position :"; (i,j);;
        (* Fonction qui renvoie la position passée en argument  *)  
         
        let ouest (x,y) = if(x=1) then (9 , y )  else (x-1,y)    ;;
        let est (x,y)= if(x=9 ) then (1 , y)  else (x-1,y)    ;;
        let sud (x,y) = if(x=9) then (1 , y)  else (x,y-1);;
        let nord (x,y) =if( y=9 ) then (x , 1) else (x, y+1)  ;;

        (* la position d'un element *)
         let at_pos  f ( p:pos) = List.filter (fun x -> f x = p);;
       
        let rec obj_by_pos f obj ll = match ll with
               [] -> [[obj]]
               |lt::llq-> if (f obj)=(f (List.hd lt)) then (obj::lt)::llq 
                                else lt::(obj_by_pos f obj llq);;
               
        let rec  sort_by_pos_aux f l_ob ll = match l_ob with
            [] -> ll
            |x :: tl ->sort_by_pos_aux f tl  (obj_by_pos f x ll)  ;;
	
        let sort_by_pos f l_obj   = sort_by_pos_aux f l_obj  [[]] ;;
        
        let display  f (x,y) = f x y  ;;
        let clear () = ()   ;;
        let affiche_pos (a,b) = print_int  a ; print_int b;; 
        let affiche_age age = string_of_age age;; 
end;;
(**************************************************************)
(* Génétique élémentaire 7 : question 11                      *)
(**************************************************************) 

module type INDIVIDU = 
sig
  type pos
  type individu
  val egalite : individu->individu ->bool
  val creer_individu : unit -> individu
  val position : individu -> pos
  val sexe : individu-> sexe
  val age : individu-> age
  val manger: int->individu->individu option
  val bouger:(pos-> int)-> individu ->individu option
  val reproduire: int->individu ->individu-> individu list 
  val vieillir: individu -> individu option
  val affiche : individu -> unit
end;;



(**************************************************************)
(* Génétique élémentaire 7 : question 12          *)
(**************************************************************) 

module type MAKE_INDIVIDU = functor (P : PLANETE) ->  INDIVIDU with type pos =P.pos ;;

(******************************************************************************)     
(* question 13: module Make_zebre qui possede la signature MAKE_INDIVIDU ******)     
(******************************************************************************)     
module MAKE_Zherb= functor (P:PLANETE) -> 
struct
   
	  
	  let last_id= ref 0
 
          (* type pos= P.pos *)
	  (*type zherb*)
          type zherb = {id: int; pos: pos ; age: age };;

          let egalite ind1 ind2 = if(ind1.id= ind2.id) then true else false;;
	  let manger i z = Some  {id= i ;pos=z.pos; age=z.age};;        
	  let bouger i z = Some  {id= i ;pos=z.pos; age=z.age};;        
	
	  (*tour de vie: viellir  *)
	  let viellissement indiv_ = 
	                   let age= indiv_.age in
			   match age with
			    Bebe -> Some  {id= indiv_.id;pos=indiv_.pos; age= Enfant}
			   |Enfant -> Some {id= indiv_.id;pos=indiv_.pos; age= Adulte}
			   |Adulte -> None;;
	  
 
          (*fonctions pour acceder aux champs(position et age) de l'enregistrement*)
	  let  position zherb_ = zherb_.pos ;;  
          let age  zherb_ = zherb_.age ;;
	  (* getSexe leve une exception *) 
	  exception Sexe_Not_Exist;;
	  (*creation d'individu zherb !*)
          let creer_zherb  ()= last_id := (!last_id+1); 
                    {id = !last_id ; pos=P.random_pos()  ; age=random_age ()};; 
	            
          (*list de liste de zherb *)
          let z1=  creer_zherb  ();; 
	  let z2= creer_zherb  ();;
	  let z3=  creer_zherb  ();; 
	  let z4= creer_zherb  ();;
          let mes_zerbs= z1::z2::z3::z4::[];; 
          
	  (*créer un enfant zherbe *)
          let creer_bebe_zherb  mere  = last_id := (!last_id+1);    
                   {id = !last_id ; pos= let position= Random.int(10) in 
                                              match position with 

                                              |0 -> P.est mere.pos
				              |1 ->  P.nord mere.pos
				              |2 -> P.sud  mere.pos
				              |3 -> P.ouest mere.pos	
				              |_ -> mere.pos  ; age= Bebe};;
	  (*creer un bebe dans la meme position que sa mere à 10%*)
	  let b1= creer_bebe_zherb z ;;   
          (*créer n enfants  zherbe *)

	  let rec liste_bebe_zherb creer_bebe_zherb mere population  =  
       if (population= 0) then [] 
       else (creer_bebe_zherb mere) ::( liste_bebe_zherb creer_bebe_zherb mere (population -1));;

          (*let bebe_zherb = liste_bebe_zherb creer_bebe_zherb z1 5;;*)
          (*la population qui se trouve dans la case de parents *)
          
	  (*la reproduction de zherb 10% positio on suppose que z1 est adulte*)
	  let  reproduire i z1 ?z2 =  match i with
	             | 0 -> []
	             | n  -> liste_bebe_zherb  creer_bebe_zherb z1 Random.int(n) ;;
  	      
	 (* let  affiche individu_zherb = print_newline();
	                                  print_int individu_zherb.id ; print_char ' ';
                                          P.affiche_age individu_zherb.age  ; print_char ' ';
                                          P.affiche_pos individu_zherb.pos ;;*)
Erreur : Error: This expression has type P.pos but an expression was expected of type
pos = int * int
#