2

The following definition is rejected by Lean:

inductive natlist
| nil : natlist
| cons: natlist → ℕ → natlist

with the error message "arg #2 of 'natlist.cons' is not recursive, but it occurs after recursive arguments"

And the following definition is accepted, as expected:

inductive natlist
| nil : natlist
| cons: ℕ → natlist → natlist

What is the reason Lean enforces this order?

Phil
  • 5,595
  • 5
  • 35
  • 55

1 Answers1

3

Lean's implementation of inductive types is based on the "Inductive families" paper by P. Dybjer (1994):

Backhouse [Bac88] and Coquand and Paulin [COP90] allowed the inessential generalisation where recursive premises may precede non-recursive ones. I prefer to put all non-recursive premises before the recursive ones, since the former cannot depend on the latter here (but the situation changes in [Dyb92]). This restriction simplifies the presentation of the scheme and emphasises the relationship with the well-orderings.

Note that a recent commit removes this restriction and your first definition works now.

Anton Trunov
  • 15,074
  • 2
  • 23
  • 43
  • 2
    I see your point. However, some people like to define the node part of binary trees like so: `| node : bintree A -> A -> bintree A -> bintree A` :) – Anton Trunov Jan 21 '17 at 21:25