400 fun case_tr context [t, u] = |
400 fun case_tr context [t, u] = |
401 let |
401 let |
402 val thy = Context.theory_of context; |
402 val thy = Context.theory_of context; |
403 fun case_error s name ts = raise TERM ("Error in case expression" ^ |
403 fun case_error s name ts = raise TERM ("Error in case expression" ^ |
404 getOpt (Option.map (curry op ^ " for datatype ") name, "") ^ ":\n" ^ s, ts); |
404 getOpt (Option.map (curry op ^ " for datatype ") name, "") ^ ":\n" ^ s, ts); |
405 fun dest_case1 (Const ("_case1", _) $ t $ u) = (case strip_comb t of |
405 fun dest_case1 (Const ("_case1", _) $ t $ u) = |
406 (Const (s, _), ts) => (((perhaps o try o unprefix) Syntax.constN o Sign.intern_const thy) s, ts) |
406 (case strip_comb t of |
|
407 (Const (s, _), ts) => |
|
408 (case try (unprefix Syntax.constN) s of |
|
409 SOME c => (c, ts) |
|
410 | NONE => (Sign.intern_const thy s, ts)) |
407 | (Free (s, _), ts) => (Sign.intern_const thy s, ts) (*FIXME?*) |
411 | (Free (s, _), ts) => (Sign.intern_const thy s, ts) (*FIXME?*) |
408 | _ => case_error "Head is not a constructor" NONE [t, u], u) |
412 | _ => case_error "Head is not a constructor" NONE [t, u], u) |
409 | dest_case1 t = raise TERM ("dest_case1", [t]); |
413 | dest_case1 t = raise TERM ("dest_case1", [t]); |
410 fun dest_case2 (Const ("_case2", _) $ t $ u) = t :: dest_case2 u |
414 fun dest_case2 (Const ("_case2", _) $ t $ u) = t :: dest_case2 u |
411 | dest_case2 t = [t]; |
415 | dest_case2 t = [t]; |