src/Pure/facts.ML
changeset 63337 ae9330fdbc16
parent 63255 3f594efa9504
child 63369 4698dd1106ae
equal deleted inserted replaced
63336:054a92af0f2b 63337:ae9330fdbc16
    34   val retrieve: Context.generic -> T -> xstring * Position.T ->
    34   val retrieve: Context.generic -> T -> xstring * Position.T ->
    35     {name: string, dynamic: bool, thms: thm list}
    35     {name: string, dynamic: bool, thms: thm list}
    36   val fold_static: (string * thm list -> 'a -> 'a) -> T -> 'a -> 'a
    36   val fold_static: (string * thm list -> 'a -> 'a) -> T -> 'a -> 'a
    37   val dest_static: bool -> T list -> T -> (string * thm list) list
    37   val dest_static: bool -> T list -> T -> (string * thm list) list
    38   val dest_all: Context.generic -> bool -> T list -> T -> (string * thm list) list
    38   val dest_all: Context.generic -> bool -> T list -> T -> (string * thm list) list
    39   val props: T -> thm list
    39   val props: T -> (thm * Position.T) list
    40   val could_unify: T -> term -> thm list
    40   val could_unify: T -> term -> (thm * Position.T) list
    41   val merge: T * T -> T
    41   val merge: T * T -> T
    42   val add_static: Context.generic -> {strict: bool, index: bool} ->
    42   val add_static: Context.generic -> {strict: bool, index: bool} ->
    43     binding * thm list -> T -> string * T
    43     binding * thm list -> T -> string * T
    44   val add_dynamic: Context.generic -> binding * (Context.generic -> thm list) -> T -> string * T
    44   val add_dynamic: Context.generic -> binding * (Context.generic -> thm list) -> T -> string * T
    45   val del: string -> T -> T
    45   val del: string -> T -> T
   132 
   132 
   133 datatype fact = Static of thm list | Dynamic of Context.generic -> thm list;
   133 datatype fact = Static of thm list | Dynamic of Context.generic -> thm list;
   134 
   134 
   135 datatype T = Facts of
   135 datatype T = Facts of
   136  {facts: fact Name_Space.table,
   136  {facts: fact Name_Space.table,
   137   props: thm Net.net};
   137   props: (thm * Position.T) Net.net};
   138 
   138 
   139 fun make_facts facts props = Facts {facts = facts, props = props};
   139 fun make_facts facts props = Facts {facts = facts, props = props};
   140 
   140 
   141 val empty = make_facts (Name_Space.empty_table "fact") Net.empty;
   141 val empty = make_facts (Name_Space.empty_table "fact") Net.empty;
   142 
   142 
   225 end;
   225 end;
   226 
   226 
   227 
   227 
   228 (* indexed props *)
   228 (* indexed props *)
   229 
   229 
   230 val prop_ord = Term_Ord.term_ord o apply2 Thm.full_prop_of;
   230 val prop_ord = Term_Ord.term_ord o apply2 (Thm.full_prop_of o fst);
   231 
   231 
   232 fun props (Facts {props, ...}) = sort_distinct prop_ord (Net.content props);
   232 fun props (Facts {props, ...}) = sort_distinct prop_ord (Net.content props);
   233 fun could_unify (Facts {props, ...}) = Net.unify_term props;
   233 fun could_unify (Facts {props, ...}) = Net.unify_term props;
   234 
   234 
   235 
   235 
   248 (* add static entries *)
   248 (* add static entries *)
   249 
   249 
   250 fun add_static context {strict, index} (b, ths) (Facts {facts, props}) =
   250 fun add_static context {strict, index} (b, ths) (Facts {facts, props}) =
   251   let
   251   let
   252     val ths' = map Thm.trim_context ths;
   252     val ths' = map Thm.trim_context ths;
       
   253     val pos = #2 (Position.default (Binding.pos_of b));
       
   254 
   253     val (name, facts') =
   255     val (name, facts') =
   254       if Binding.is_empty b then ("", facts)
   256       if Binding.is_empty b then ("", facts)
   255       else Name_Space.define context strict (b, Static ths') facts;
   257       else Name_Space.define context strict (b, Static ths') facts;
   256     val props' = props
   258     val props' = props
   257       |> index ? fold (fn th => Net.insert_term (K false) (Thm.full_prop_of th, th)) ths';
   259       |> index ? fold (fn th => Net.insert_term (K false) (Thm.full_prop_of th, (th, pos))) ths';
   258   in (name, make_facts facts' props') end;
   260   in (name, make_facts facts' props') end;
   259 
   261 
   260 
   262 
   261 (* add dynamic entries *)
   263 (* add dynamic entries *)
   262 
   264