src/Pure/term.ML
changeset 19455 d828bfab05af
parent 19394 9f69613362c1
child 19473 d87a8838afa4
     1.1 --- a/src/Pure/term.ML	Mon Apr 24 16:35:30 2006 +0200
     1.2 +++ b/src/Pure/term.ML	Mon Apr 24 16:36:07 2006 +0200
     1.3 @@ -209,6 +209,8 @@
     1.4    val adhoc_freeze_vars: term -> term * string list
     1.5    val string_of_vname: indexname -> string
     1.6    val string_of_vname': indexname -> string
     1.7 +  val str_of_sort: sort -> string
     1.8 +  val str_of_typ: typ -> string
     1.9    val str_of_term: term -> string
    1.10  end;
    1.11  
    1.12 @@ -1312,8 +1314,6 @@
    1.13    in (subst_atomic insts tm, xs) end;
    1.14  
    1.15  
    1.16 -(* string_of_vname *)
    1.17 -
    1.18  val show_question_marks = ref true;
    1.19  
    1.20  fun string_of_vname (x, i) =
    1.21 @@ -1335,15 +1335,36 @@
    1.22  fun string_of_vname' (x, ~1) = x
    1.23    | string_of_vname' xi = string_of_vname xi;
    1.24  
    1.25 -
    1.26 -(* str_of_term *)
    1.27 +fun str_of_sort [] = "{}"
    1.28 +  | str_of_sort [c] = c
    1.29 +  | str_of_sort cs = (enclose "{" "}" o commas) cs
    1.30  
    1.31 -fun str_of_term (Const (c, _)) = c
    1.32 -  | str_of_term (Free (x, _)) = x
    1.33 -  | str_of_term (Var (xi, _)) = string_of_vname xi
    1.34 -  | str_of_term (Bound i) = string_of_int i
    1.35 -  | str_of_term (Abs (x, _, t)) = "%" ^ x ^ ". " ^ str_of_term t
    1.36 -  | str_of_term (t $ u) = "(" ^ str_of_term t ^ " " ^ str_of_term u ^ ")";
    1.37 +fun str_of_typ (Type ("fun", [ty1, ty2])) =
    1.38 +      "(" ^ str_of_typ ty1 ^ " => " ^ str_of_typ ty2 ^ ")"
    1.39 +  | str_of_typ (Type ("dummy", [])) =
    1.40 +      "_"
    1.41 +  | str_of_typ (Type (tyco, _)) =
    1.42 +      tyco
    1.43 +  | str_of_typ (Type (tyco, tys)) =
    1.44 +      (enclose "(" ")" o space_implode " ") (tyco :: map str_of_typ tys)
    1.45 +  | str_of_typ (TFree (v, sort)) =
    1.46 +      v ^ "::" ^ str_of_sort sort
    1.47 +  | str_of_typ (TVar (vi, sort)) =
    1.48 +      string_of_vname vi ^ "::" ^ str_of_sort sort;
    1.49 +
    1.50 +val str_of_term =
    1.51 +  let
    1.52 +    fun typed (s, ty) = s ^ "::" ^ str_of_typ ty;
    1.53 +    fun bound vs i = case AList.lookup (op =) vs i
    1.54 +     of SOME v => enclose "[" "]" (string_of_int i ^ " ~> " ^ v)
    1.55 +      | NONE => (enclose "[" "]" o string_of_int) i
    1.56 +    fun str vs (Const (c, _)) = c
    1.57 +      | str vs (Free (v, ty)) = typed (v, ty)
    1.58 +      | str vs (Var (vi, ty)) = typed (string_of_vname vi, ty)
    1.59 +      | str vs (Bound i) = bound vs i
    1.60 +      | str vs (Abs (x, ty, t)) = "(%" ^ typed (x, ty) ^ ". " ^ str ((length vs, x)::vs) t ^ ")"
    1.61 +      | str vs (t1 $ t2) = "(" ^ str vs t1 ^ " " ^ str vs t2 ^ ")";
    1.62 +  in str [] end;
    1.63  
    1.64  end;
    1.65