feat(kernel): add function param_names_to_levels

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-02 16:17:04 -07:00
parent 96f639811c
commit 82e1f87e08
4 changed files with 8 additions and 3 deletions

View file

@ -187,7 +187,7 @@ struct add_inductive_fn {
m_env(env), m_level_names(level_params), m_num_params(num_params), m_decls(decls), m_env(env), m_level_names(level_params), m_num_params(num_params), m_decls(decls),
m_ngen(g_tmp_prefix), m_tc(m_env) { m_ngen(g_tmp_prefix), m_tc(m_env) {
m_decls_sz = length(m_decls); m_decls_sz = length(m_decls);
m_levels = map2<level>(level_params, [](name const & n) { return mk_param_univ(n); }); m_levels = param_names_to_levels(level_params);
} }
/** \brief Return the number of inductive datatypes being defined. */ /** \brief Return the number of inductive datatypes being defined. */

View file

@ -686,5 +686,8 @@ bool is_geq_core(level l1, level l2) {
bool is_geq(level const & l1, level const & l2) { bool is_geq(level const & l1, level const & l2) {
return is_geq_core(normalize(l1), normalize(l2)); return is_geq_core(normalize(l1), normalize(l2));
} }
levels param_names_to_levels(level_param_names const & ps) {
return map2<level>(ps, [](name const & p) { return mk_param_univ(p); });
}
} }
void print(lean::level const & l) { std::cout << l << std::endl; } void print(lean::level const & l) { std::cout << l << std::endl; }

View file

@ -218,5 +218,7 @@ format pp(level const & l, options const & opts = options());
format pp(level const & lhs, level const & rhs, bool unicode, unsigned indent); format pp(level const & lhs, level const & rhs, bool unicode, unsigned indent);
/** \brief Pretty print lhs <= rhs using the given configuration options. */ /** \brief Pretty print lhs <= rhs using the given configuration options. */
format pp(level const & lhs, level const & rhs, options const & opts = options()); format pp(level const & lhs, level const & rhs, options const & opts = options());
/** \brief Convert a list of universe level parameter names into a list of levels. */
levels param_names_to_levels(level_param_names const & ps);
} }
void print(lean::level const & l); void print(lean::level const & l);

View file

@ -39,7 +39,7 @@ struct decl_info {
decl_info(unsigned pos, level_param_names const & lvl_deps, dependencies const & var_deps, expr const & type, decl_info(unsigned pos, level_param_names const & lvl_deps, dependencies const & var_deps, expr const & type,
binder_info const & bi, bool local): binder_info const & bi, bool local):
m_pos(pos), m_level_deps(lvl_deps), m_var_deps(var_deps), m_type(type), m_binder_info(bi), m_local(local) { m_pos(pos), m_level_deps(lvl_deps), m_var_deps(var_deps), m_type(type), m_binder_info(bi), m_local(local) {
m_levels = map2<level>(m_level_deps, [](name const & n) { return mk_param_univ(n); }); m_levels = param_names_to_levels(m_level_deps);
} }
}; };
@ -342,7 +342,7 @@ environment add_inductive(environment env,
} }
// collect new params and level_params // collect new params and level_params
level_param_names extra_ls = ctx.mk_level_deps(); level_param_names extra_ls = ctx.mk_level_deps();
levels extra_lvls = map2<level>(extra_ls, [](name const & n) { return mk_param_univ(n); }); levels extra_lvls = param_names_to_levels(extra_ls);
dependencies extra_ps = ctx.mk_var_deps(); dependencies extra_ps = ctx.mk_var_deps();
unsigned new_num_params = num_params + extra_ps.size(); unsigned new_num_params = num_params + extra_ps.size();
level_param_names new_ls = append(extra_ls, s_level_params); level_param_names new_ls = append(extra_ls, s_level_params);