open Ast open Printf let pp_binder = function | `Lambda -> "lambda" | `Pi -> "pi" | `Exists -> "exists" | `Forall -> "forall" let rec pp_term = function | LocatedTerm ((p_begin, p_end), term) -> sprintf "[%d,%d]%s" p_begin p_end (pp_term term) | Appl terms -> sprintf "(%s)" (String.concat " " (List.map pp_term terms)) | Binder (kind, var, typ, body) -> sprintf "\\%s %s%s.%s" (pp_binder kind) var (match typ with None -> "" | Some typ -> ": " ^ pp_term typ) (pp_term body) | Case (term, typ, patterns) -> sprintf "%smatch %s with %s" (match typ with None -> "" | Some t -> sprintf "<%s>" (pp_term t)) (pp_term term) (pp_patterns patterns) | LetIn (name, t1, t2) -> sprintf "let %s = %s in %s" name (pp_term t1) (pp_term t2) | LetRec (definitions, term) -> sprintf "let rec %s in %s" (String.concat " and " (List.map (fun (name, body, typ, index) -> sprintf "%s%s = %s" name (match typ with None -> "" | Some typ -> ": " ^ pp_term typ) (pp_term body)) definitions)) (pp_term term) | Ident (name, []) -> name | Ident (name, substs) -> sprintf "%s[%s]" name (pp_substs substs) | Meta (name, substs) -> sprintf "%s[%s]" name (String.concat "; " (List.map (function None -> "_" | Some term -> pp_term term) substs)) | Int num -> string_of_int num and pp_subst (name, term) = sprintf "%s := %s" name (pp_term term) and pp_substs substs = String.concat "; " (List.map pp_subst substs) and pp_pattern (names, term) = sprintf "%s -> %s" (match names with | [n] -> n | names -> "(" ^ String.concat " " names ^ ")") (pp_term term) and pp_patterns patterns = sprintf "[%s]" (String.concat " | " (List.map pp_pattern patterns))