33 (*************************************************************************) |
33 (*************************************************************************) |
34 (***************************** building types ****************************) |
34 (***************************** building types ****************************) |
35 (*************************************************************************) |
35 (*************************************************************************) |
36 |
36 |
37 (* ->> is taken from holcf_logic.ML *) |
37 (* ->> is taken from holcf_logic.ML *) |
38 fun cfunT (T, U) = Type(@{type_name "->"}, [T, U]); |
38 fun cfunT (T, U) = Type(@{type_name cfun}, [T, U]); |
39 |
39 |
40 infixr 6 ->>; val (op ->>) = cfunT; |
40 infixr 6 ->>; val (op ->>) = cfunT; |
41 |
41 |
42 fun dest_cfunT (Type(@{type_name "->"}, [T, U])) = (T, U) |
42 fun dest_cfunT (Type(@{type_name cfun}, [T, U])) = (T, U) |
43 | dest_cfunT T = raise TYPE ("dest_cfunT", [T], []); |
43 | dest_cfunT T = raise TYPE ("dest_cfunT", [T], []); |
44 |
44 |
45 fun maybeT T = Type(@{type_name "maybe"}, [T]); |
45 fun maybeT T = Type(@{type_name "maybe"}, [T]); |
46 |
46 |
47 fun dest_maybeT (Type(@{type_name "maybe"}, [T])) = T |
47 fun dest_maybeT (Type(@{type_name "maybe"}, [T])) = T |
51 | tupleT [T] = T |
51 | tupleT [T] = T |
52 | tupleT (T :: Ts) = HOLogic.mk_prodT (T, tupleT Ts); |
52 | tupleT (T :: Ts) = HOLogic.mk_prodT (T, tupleT Ts); |
53 |
53 |
54 local |
54 local |
55 |
55 |
56 fun binder_cfun (Type(@{type_name "->"},[T, U])) = T :: binder_cfun U |
56 fun binder_cfun (Type(@{type_name cfun},[T, U])) = T :: binder_cfun U |
57 | binder_cfun (Type(@{type_name "fun"},[T, U])) = T :: binder_cfun U |
57 | binder_cfun (Type(@{type_name "fun"},[T, U])) = T :: binder_cfun U |
58 | binder_cfun _ = []; |
58 | binder_cfun _ = []; |
59 |
59 |
60 fun body_cfun (Type(@{type_name "->"},[T, U])) = body_cfun U |
60 fun body_cfun (Type(@{type_name cfun},[T, U])) = body_cfun U |
61 | body_cfun (Type(@{type_name "fun"},[T, U])) = body_cfun U |
61 | body_cfun (Type(@{type_name "fun"},[T, U])) = body_cfun U |
62 | body_cfun T = T; |
62 | body_cfun T = T; |
63 |
63 |
64 fun strip_cfun T : typ list * typ = |
64 fun strip_cfun T : typ list * typ = |
65 (binder_cfun T, body_cfun T); |
65 (binder_cfun T, body_cfun T); |
97 in cabs_const (Term.domain_type T, Term.range_type T) $ t end |
97 in cabs_const (Term.domain_type T, Term.range_type T) $ t end |
98 |
98 |
99 fun mk_capply (t, u) = |
99 fun mk_capply (t, u) = |
100 let val (S, T) = |
100 let val (S, T) = |
101 case Term.fastype_of t of |
101 case Term.fastype_of t of |
102 Type(@{type_name "->"}, [S, T]) => (S, T) |
102 Type(@{type_name cfun}, [S, T]) => (S, T) |
103 | _ => raise TERM ("mk_capply " ^ ML_Syntax.print_list ML_Syntax.print_term [t, u], [t, u]); |
103 | _ => raise TERM ("mk_capply " ^ ML_Syntax.print_list ML_Syntax.print_term [t, u], [t, u]); |
104 in capply_const (S, T) $ t $ u end; |
104 in capply_const (S, T) $ t $ u end; |
105 |
105 |
106 infix 0 ==; val (op ==) = Logic.mk_equals; |
106 infix 0 ==; val (op ==) = Logic.mk_equals; |
107 infix 1 ===; val (op ===) = HOLogic.mk_eq; |
107 infix 1 ===; val (op ===) = HOLogic.mk_eq; |
286 let val (rhs', v, taken') = pre_build match_name x rhs [] taken; |
286 let val (rhs', v, taken') = pre_build match_name x rhs [] taken; |
287 in pre_build match_name f rhs' (v::vs) taken' end |
287 in pre_build match_name f rhs' (v::vs) taken' end |
288 | Const(c,T) => |
288 | Const(c,T) => |
289 let |
289 let |
290 val n = Name.variant taken "v"; |
290 val n = Name.variant taken "v"; |
291 fun result_type (Type(@{type_name "->"},[_,T])) (x::xs) = result_type T xs |
291 fun result_type (Type(@{type_name cfun},[_,T])) (x::xs) = result_type T xs |
292 | result_type (Type (@{type_name "fun"},[_,T])) (x::xs) = result_type T xs |
292 | result_type (Type (@{type_name "fun"},[_,T])) (x::xs) = result_type T xs |
293 | result_type T _ = T; |
293 | result_type T _ = T; |
294 val v = Free(n, result_type T vs); |
294 val v = Free(n, result_type T vs); |
295 val m = Const(match_name c, matchT (T, fastype_of rhs)); |
295 val m = Const(match_name c, matchT (T, fastype_of rhs)); |
296 val k = big_lambdas vs rhs; |
296 val k = big_lambdas vs rhs; |