(* Impression *) open Lo open Num let string_of_variable = function | Variable_textuelle s -> s | Variable_abstraite i -> "_" ^ string_of_int i let rec string_of_type = function | Type_reel -> "R" | Type_bool -> "bool" | Type_nat -> "nat" | Type_fleche (a, b) -> "(" ^ string_of_type a ^ " -> " ^ string_of_type b ^ ")" | Type_couple (a, b) -> "(" ^ string_of_type a ^ " * " ^ string_of_type b ^ ")" | Type_o a -> "(O " ^ string_of_type a ^ ")" let rec string_of_terme = function | Terme_spec s -> string_of_spec s | Terme_variable v -> string_of_variable v | Terme_valeur v -> string_of_valeur v | Terme_application ( Terme_application ( Terme_spec ( { spec_nom_infixe = Some op; spec_scope = ty; } ), a ), b ) -> "(" ^ string_of_terme a ^ " " ^ op ^ " " ^ string_of_terme b ^ ")%" ^ string_of_type ty | Terme_application (m1, m2) -> "(" ^ string_of_terme m1 ^ " " ^ string_of_terme m2 ^ ")" | Terme_couple (m1, m2) -> "(" ^ string_of_terme m1 ^ ", " ^ string_of_terme m2 ^ ")" | Terme_fst m -> "(fst " ^ string_of_terme m ^ ")" | Terme_snd m -> "(snd " ^ string_of_terme m ^ ")" | Terme_fix ((f, t), m) -> "(fix " ^ string_of_variable f ^ " : " ^ string_of_type t ^ " := " ^ string_of_terme m ^ ")" | Terme_si (cond, (vt, vf)) -> "(if " ^ string_of_terme cond ^ " then " ^ string_of_terme vt ^ " else " ^ string_of_terme vf ^ ")" | Terme_egale (t1, t2) -> "(" ^ string_of_terme t1 ^ " = " ^ string_of_terme t2 ^ ")" and string_of_valeur = function | Valeur_prob e -> "(prob " ^ string_of_expr e ^ ")" | Valeur_lambda ((x, a), m) -> "(fun " ^ string_of_variable x ^ " : " ^ string_of_type a ^ " => " ^ string_of_terme m ^ ")" | Valeur_reelle r -> string_of_reel r | Valeur_nat n -> string_of_naturel n | Valeur_bool true -> "true" | Valeur_bool false -> "false" | Valeur_fonct (t, _) -> string_of_terme t | Valeur_couple (a1, a2) -> "(" ^ string_of_valeur a1 ^ ", " ^ string_of_valeur a2 ^ ")" and string_of_expr = function | Expr_terme m -> string_of_terme m | Expr_sample ((x, m), e) -> "sample " ^ string_of_variable x ^ " from " ^ string_of_terme m ^ " in " ^ string_of_expr e | Expr_s -> "S"