Application of universes: staged metaprogramming

Let and be a universe with products and unit type. Then if is a meta-level type of natural numbers, we can define

Loop unrolling for compile-time-known

Note that need not have dependent types or even function types for this to work. See [Kiselyov 2014Kiselyov, O. 2014. The Design and Implementation of BER MetaOCaml: System Description. In: Functional and Logic Programming. Springer International Publishing, 86–102., Kovács 2022Kovács, A. 2022. Staged compilation with two-level type theory. Proceedings of the ACM on Programming Languages 6, 540–569. http://dx.doi.org/10.1145/3547641.]