 
 
 
1.8   Environnement initial
Le langage mini-ML possède un certain nombre de fonctions prédéfinies. Ces fonctions
munies de leur type correspondent à l'environnement initial de typage. Il peut être
créé de la manière suivante :
# let initial_typing_env =
   let mk_type (ct1,ct2,ct3) =
     Forall([],
      Fun_type (Pair_type(Const_type ct1, Const_type ct2),Const_type ct3))
   in
     let int_ftype = mk_type(Int_type,Int_type,Int_type)
     and float_ftype = mk_type(Float_type,Float_type,Float_type)
     and int_predtype = mk_type(Int_type,Int_type,Bool_type)
     and float_predtype = mk_type(Float_type,Float_type,Bool_type)
     and alpha = Var_type(ref(Unknown 1))
     and beta = Var_type(ref(Unknown 2))
     in
       ("=",Forall([ 1 ],
          Fun_type (Pair_type (alpha,alpha), Const_type Bool_type)))::
       (List.map (function s -> (s,int_ftype))
          [ "*"; "+"; "-"; "/" ]) @
       (List.map (function s -> (s,float_ftype))
          [ "*."; "+."; "-."; "/." ]) @
       (List.map (function s -> (s,int_predtype))
          [ "<"; ">"; "<="; ">=" ]) @
       (List.map (function s -> (s,float_predtype))
          [ "<."; ">."; "<=."; ">=." ]) @
     [ "^", mk_type (String_type, String_type, String_type) ] @
     [ ("hd",Forall([ 1 ], Fun_type (List_type alpha, alpha)));
     ("tl",Forall([ 1 ], Fun_type (List_type alpha, List_type alpha)));
     ("null",Forall([ 1 ], Fun_type (alpha,
     Fun_type (List_type alpha, Const_type Bool_type))));
     ("fst",Forall([ 1; 2 ], Fun_type (Pair_type (alpha,beta),alpha)));
     ("snd",Forall([ 1; 2 ], Fun_type (Pair_type (alpha,beta),beta))) ]
     ;; 
val initial_typing_env : (string * quantified_type) list =
  ["=", Forall ([1], Fun_type (Pair_type (...), Const_type ...));
   "*", Forall ([], Fun_type (Pair_type (...), Const_type ...)); ...]
 
 
