You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
1.2 KiB

open Lang
let fprintf_literal fmt = function
| Unit ->
Format.fprintf fmt "unit"
| Bool b ->
Format.fprintf fmt "%B" b
let fprintf_const fmt = function
| Literal l ->
Format.fprintf fmt "%a" fprintf_literal l
| Var v ->
Format.fprintf fmt "%s" v
let fprintf_pattern fmt p = Format.fprintf fmt "%s" p
let rec fprintf_expr fmt = function
| Const c ->
fprintf_const fmt c
| Bind (p, e, e') ->
Format.fprintf fmt "let %a = %a in %a" fprintf_pattern p fprintf_expr e
fprintf_expr e'
| Abstract (p, e) ->
Format.fprintf fmt "(fun %a -> %a)" fprintf_pattern p fprintf_expr e
| Apply (e, e') ->
Format.fprintf fmt "%a %a" fprintf_expr e fprintf_expr e'
let fprintf_file fmt f = Format.fprintf fmt "%a@." fprintf_expr f
let fprintf_primitive_type fmt = function
| Types.Unit ->
Format.fprintf fmt "unit"
| Types.Bool ->
Format.fprintf fmt "bool"
let rec fprintf_type fmt = function
| Types.Variable x ->
Format.fprintf fmt "%s" x
| Types.Primitive t ->
fprintf_primitive_type fmt t
| Types.Arrow (t1, t2) ->
Format.fprintf fmt "(%a -> %a)" fprintf_type t1 fprintf_type t2