MCPcopy Create free account
hub / github.com/argumentcomputer/ix / nat_env

Function nat_env

crates/kernel/src/inductive.rs:4735–4862  ·  view source on GitHub ↗

Build env with Nat (1 recursive ctor) and its recursor. Nat : Sort 1 Nat.zero : Nat Nat.succ : Nat → Nat Nat.rec : ∀ (motive : Nat → Sort u) (zero : motive Nat.zero) (succ : ∀ (n : Nat), motive n → motive (Nat.succ n)) (t : Nat), motive t

()

Source from the content-addressed store, hash-verified

4733 let mut env = bool_env();
4734 let mut tc = TypeChecker::new(&mut env);
4735 assert!(tc.check_const(&mk_id("Bool")).is_ok());
4736 }
4737
4738 #[test]
4739 fn check_inductive_rejects_ctor_param_count_mismatch() {
4740 let mut env = bool_env();
4741 env.insert(
4742 mk_id("Bool.true"),
4743 KConst::Ctor {
4744 name: (),
4745 level_params: (),
4746 is_unsafe: false,
4747 lvls: 0,
4748 induct: mk_id("Bool"),
4749 cidx: 0,
4750 params: 1,
4751 fields: 0,
4752 ty: cnst("Bool", &[]),
4753 },
4754 );
4755
4756 let mut tc = TypeChecker::new(&mut env);
4757 match tc.check_const(&mk_id("Bool")) {
4758 Err(TcError::Other(s)) => assert!(s.contains("ctor params mismatch")),
4759 other => panic!("expected ctor params mismatch, got {other:?}"),
4760 }
4761 }
4762
4763 #[test]
4764 fn check_bool_constructor_uses_parent_block() {
4765 let mut env = bool_env();
4766 let mut tc = TypeChecker::new(&mut env);
4767 tc.check_const(&mk_id("Bool.true")).unwrap();
4768 assert!(
4769 env.block_check_results.get(&mk_id("Bool")).is_some_and(|r| r.is_ok())
4770 );
4771 }
4772
4773 #[test]
4774 fn check_bool_rec() {
4775 let mut env = bool_env();
4776 let mut tc = TypeChecker::new(&mut env);
4777 // Must check inductive first to trigger recursor generation
4778 tc.check_const(&mk_id("Bool")).unwrap();
4779 assert!(tc.check_const(&mk_id("Bool.rec")).is_ok(), "Bool.rec should pass");
4780 }
4781
4782 /// Build env with Nat (1 recursive ctor) and its recursor.
4783 /// Nat : Sort 1
4784 /// Nat.zero : Nat
4785 /// Nat.succ : Nat → Nat
4786 /// Nat.rec : ∀ (motive : Nat → Sort u) (zero : motive Nat.zero)
4787 /// (succ : ∀ (n : Nat), motive n → motive (Nat.succ n))
4788 /// (t : Nat), motive t
4789 fn nat_env() -> KEnv<Anon> {
4790 let mut env = KEnv::new();
4791 let block = mk_id("Nat");
4792 let rec_block = mk_id("Nat.rec.block");

Callers 2

check_nat_recFunction · 0.70
nat_rec_rulesFunction · 0.70

Calls 12

sortFunction · 0.85
mk_idFunction · 0.70
cnstFunction · 0.70
sort1Function · 0.70
natFunction · 0.70
piFunction · 0.70
paramFunction · 0.70
appFunction · 0.70
varFunction · 0.70
lamFunction · 0.70
insertMethod · 0.45
cloneMethod · 0.45

Tested by 2

check_nat_recFunction · 0.56
nat_rec_rulesFunction · 0.56