336 end; |
336 end; |
337 |
337 |
338 |
338 |
339 (* primitive rules *) |
339 (* primitive rules *) |
340 |
340 |
341 fun add_classrel th thy = |
341 fun add_classrel raw_th thy = |
342 let |
342 let |
|
343 val th = Thm.strip_shyps (Thm.transfer thy raw_th); |
|
344 val prop = Thm.plain_prop_of th; |
343 fun err () = raise THM ("add_classrel: malformed class relation", 0, [th]); |
345 fun err () = raise THM ("add_classrel: malformed class relation", 0, [th]); |
344 val prop = Thm.plain_prop_of (Thm.transfer thy th); |
|
345 val rel = Logic.dest_classrel prop handle TERM _ => err (); |
346 val rel = Logic.dest_classrel prop handle TERM _ => err (); |
346 val (c1, c2) = cert_classrel thy rel handle TYPE _ => err (); |
347 val (c1, c2) = cert_classrel thy rel handle TYPE _ => err (); |
347 in |
348 in |
348 thy |
349 thy |
349 |> Sign.primitive_classrel (c1, c2) |
350 |> Sign.primitive_classrel (c1, c2) |
350 |> put_classrel ((c1, c2), Thm.close_derivation (Drule.unconstrainTs th)) |
351 |> put_classrel ((c1, c2), Thm.close_derivation (Drule.unconstrainTs th)) |
351 |> perhaps complete_arities |
352 |> perhaps complete_arities |
352 end; |
353 end; |
353 |
354 |
354 fun add_arity th thy = |
355 fun add_arity raw_th thy = |
355 let |
356 let |
|
357 val th = Thm.strip_shyps (Thm.transfer thy raw_th); |
|
358 val prop = Thm.plain_prop_of th; |
356 fun err () = raise THM ("add_arity: malformed type arity", 0, [th]); |
359 fun err () = raise THM ("add_arity: malformed type arity", 0, [th]); |
357 val prop = Thm.plain_prop_of (Thm.transfer thy th); |
|
358 val (t, Ss, c) = Logic.dest_arity prop handle TERM _ => err (); |
360 val (t, Ss, c) = Logic.dest_arity prop handle TERM _ => err (); |
359 val T = Type (t, map TFree (Name.names Name.context Name.aT Ss)); |
361 val T = Type (t, map TFree (Name.names Name.context Name.aT Ss)); |
360 val missing_params = Sign.complete_sort thy [c] |
362 val missing_params = Sign.complete_sort thy [c] |
361 |> maps (these o Option.map #params o try (get_info thy)) |
363 |> maps (these o Option.map #params o try (get_info thy)) |
362 |> filter_out (fn (const, _) => can (get_inst_param thy) (const, t)) |
364 |> filter_out (fn (const, _) => can (get_inst_param thy) (const, t)) |