19 datatype arity_clause = ArityClause of |
19 datatype arity_clause = ArityClause of |
20 {axiom_name: string, conclLit: arLit, premLits: arLit list} |
20 {axiom_name: string, conclLit: arLit, premLits: arLit list} |
21 datatype classrel_clause = ClassrelClause of |
21 datatype classrel_clause = ClassrelClause of |
22 {axiom_name: string, subclass: name, superclass: name} |
22 {axiom_name: string, subclass: name, superclass: name} |
23 datatype combtyp = |
23 datatype combtyp = |
24 TyVar of name | |
24 CombTVar of name | |
25 TyFree of name | |
25 CombTFree of name | |
26 TyConstr of name * combtyp list |
26 CombType of name * combtyp list |
27 datatype combterm = |
27 datatype combterm = |
28 CombConst of name * combtyp * combtyp list (* Const and Free *) | |
28 CombConst of name * combtyp * combtyp list (* Const and Free *) | |
29 CombVar of name * combtyp | |
29 CombVar of name * combtyp | |
30 CombApp of combterm * combterm |
30 CombApp of combterm * combterm |
31 datatype fol_literal = FOLLiteral of bool * combterm |
31 datatype fol_literal = FOLLiteral of bool * combterm |
350 fun make_arity_clauses thy tycons classes = |
350 fun make_arity_clauses thy tycons classes = |
351 let val (classes', cpairs) = iter_type_class_pairs thy tycons classes |
351 let val (classes', cpairs) = iter_type_class_pairs thy tycons classes |
352 in (classes', multi_arity_clause cpairs) end; |
352 in (classes', multi_arity_clause cpairs) end; |
353 |
353 |
354 datatype combtyp = |
354 datatype combtyp = |
355 TyVar of name | |
355 CombTVar of name | |
356 TyFree of name | |
356 CombTFree of name | |
357 TyConstr of name * combtyp list |
357 CombType of name * combtyp list |
358 |
358 |
359 datatype combterm = |
359 datatype combterm = |
360 CombConst of name * combtyp * combtyp list (* Const and Free *) | |
360 CombConst of name * combtyp * combtyp list (* Const and Free *) | |
361 CombVar of name * combtyp | |
361 CombVar of name * combtyp | |
362 CombApp of combterm * combterm |
362 CombApp of combterm * combterm |
370 (*********************************************************************) |
370 (*********************************************************************) |
371 (* convert a clause with type Term.term to a clause with type clause *) |
371 (* convert a clause with type Term.term to a clause with type clause *) |
372 (*********************************************************************) |
372 (*********************************************************************) |
373 |
373 |
374 (*Result of a function type; no need to check that the argument type matches.*) |
374 (*Result of a function type; no need to check that the argument type matches.*) |
375 fun result_type (TyConstr (_, [_, tp2])) = tp2 |
375 fun result_type (CombType (_, [_, tp2])) = tp2 |
376 | result_type _ = raise Fail "non-function type" |
376 | result_type _ = raise Fail "non-function type" |
377 |
377 |
378 fun type_of_combterm (CombConst (_, tp, _)) = tp |
378 fun type_of_combterm (CombConst (_, tp, _)) = tp |
379 | type_of_combterm (CombVar (_, tp)) = tp |
379 | type_of_combterm (CombVar (_, tp)) = tp |
380 | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1) |
380 | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1) |
385 | stripc x = x |
385 | stripc x = x |
386 in stripc(u,[]) end |
386 in stripc(u,[]) end |
387 |
387 |
388 fun type_of (Type (a, Ts)) = |
388 fun type_of (Type (a, Ts)) = |
389 let val (folTypes,ts) = types_of Ts in |
389 let val (folTypes,ts) = types_of Ts in |
390 (TyConstr (`make_fixed_type_const a, folTypes), ts) |
390 (CombType (`make_fixed_type_const a, folTypes), ts) |
391 end |
391 end |
392 | type_of (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp]) |
392 | type_of (tp as TFree (a, _)) = (CombTFree (`make_fixed_type_var a), [tp]) |
393 | type_of (tp as TVar (x, _)) = |
393 | type_of (tp as TVar (x, _)) = |
394 (TyVar (make_schematic_type_var x, string_of_indexname x), [tp]) |
394 (CombTVar (make_schematic_type_var x, string_of_indexname x), [tp]) |
395 and types_of Ts = |
395 and types_of Ts = |
396 let val (folTyps, ts) = ListPair.unzip (map type_of Ts) in |
396 let val (folTyps, ts) = ListPair.unzip (map type_of Ts) in |
397 (folTyps, union_all ts) |
397 (folTyps, union_all ts) |
398 end |
398 end |
399 |
399 |
400 (* same as above, but no gathering of sort information *) |
400 (* same as above, but no gathering of sort information *) |
401 fun simp_type_of (Type (a, Ts)) = |
401 fun simp_type_of (Type (a, Ts)) = |
402 TyConstr (`make_fixed_type_const a, map simp_type_of Ts) |
402 CombType (`make_fixed_type_const a, map simp_type_of Ts) |
403 | simp_type_of (TFree (a, _)) = TyFree (`make_fixed_type_var a) |
403 | simp_type_of (TFree (a, _)) = CombTFree (`make_fixed_type_var a) |
404 | simp_type_of (TVar (x, _)) = |
404 | simp_type_of (TVar (x, _)) = |
405 TyVar (make_schematic_type_var x, string_of_indexname x) |
405 CombTVar (make_schematic_type_var x, string_of_indexname x) |
406 |
406 |
407 (* convert a Term.term (with combinators) into a combterm, also accummulate sort info *) |
407 (* convert a Term.term (with combinators) into a combterm, also accummulate sort info *) |
408 fun combterm_of thy (Const (c, T)) = |
408 fun combterm_of thy (Const (c, T)) = |
409 let |
409 let |
410 val (tp, ts) = type_of T |
410 val (tp, ts) = type_of T |