fact: Definition tmEncode (A : Type) : TemplateMonad (A -> L.term) := t <- (tmEval hnf A >>= tmQuote) ;; hs_num <- tmGetOption (split_head_symbol t) "no inductive";; let '(ind, Params) := hs_num in decl <- tmQuoteInductiveDecl (inductive_mind ind) ;; let '(mdecl,idecl) := decl in num <- tmEval cbv (| ind_ctors idecl |) ;; let params := firstn mdecl.(ind_npars) Params in f <- tmFreshName ("enc_" ++ snd (inductive_mind ind)) ;; x <- tmFreshName "x" ;; ter <- mkFixMatch f x t tTerm (mk_predicate Instance.empty params (context_to_bcontext (ind_predicate_context ind mdecl idecl)) tTerm) (fun i ctr_types => args <- tmEval cbv (|ctr_types|);; C <- monad_map_i (encode_arguments t args) ctr_types ;; ret ( (it mkLam num ((fun s => mkAppList s C) (mkVar (mkNat (num - i - 1)))))) ) ;; u <- tmUnquoteTyped (A -> L.term) ter;; ret u.
imports: Ascii String Undecidability.L(Util.L_facts) MetaCoq(Template.All Template.Checker) Undecidability.Shared.Libs.PSL.Base MetaCoq.Utils.bytestring