# Fix followed by fun

**URL:** <https://discourse.rocq-prover.org/t/fix-followed-by-fun/302>\
**Category:** Using Rocq\
**Created:** [May 24, 2019, 9:11am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302 "2019-05-24T09:11:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gert-smolka](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/gert-smolka/32/20_2.png) [@gert-smolka](https://discourse.rocq-prover.org/u/gert-smolka)\
**Post date:** [May 24, 2019, 9:11am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302/1 "2019-05-24T09:11:47Z")

</div>

A recursive abstraction (fix) followed by an lambda abstraction (fun) seems to be converted by the reader into a fix with extra arguments. For instance,

```auto
Set Printing All.
Check fix add x := fun y =>
  match x with
  | O => y
  | S x' => S (add x' y)
  end.

```

yields

```auto
fix add (x y : nat) {struct x} : nat :=
  match x return nat with
  | O => y
  | S x' => S (add x' y)
  end
     : forall (_ : nat) (_ : nat), nat

```

But it’s not just the reader, it’s a conversion rule. Consider

```auto
Definition foo :=
  fix F x := fun y => match x with
                   | O => y
                   | S x' => S y
                   end.

Definition foo' x y :=
  match x with
  | 0 => y
  | S x' => S y
  end.

Goal foo = foo'.
  Fail reflexivity.
Abort.

Goal foo = fix F x := foo' x.
reflexivity.
Qed.

```

I’m puzzled. Did this enter the kernel with \eta-conversion? Or was it there before and I’m just ignorant of the conversion rule? Or is there some other explanation? I would be very thankful for pointers. Gert

---

<div class="post-metadata">

**Author:** ![SkySkimmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/skyskimmer/32/369_2.png) [@SkySkimmer](https://discourse.rocq-prover.org/u/SkySkimmer)\
**Post date:** [May 24, 2019, 9:36am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302/2 "2019-05-24T09:36:56Z")

</div>

Internally a fixpoint is a term for the type of the fixpoint (`nat -> nat -> nat` for addition), a term for the body (`fun x y => match ...` with the fixpoint variable `add` free) and an index indicating which argument is the principal one (the first one for addition) (a bit more complicated for mutual fixpoints but same idea).  
This means that any arguments after the principal argument are not special, they’re just normal lambdas.

So a printed form which looks similar to the internal representation might be `fix add {struct 1} : nat -> nat -> nat := fun x y => match ...`. To make it look nicer we put as many arguments to the left of the `:=` as possible (and this lets us use a name instead of an index in `struct`), thus `fix add (x y : nat) {struct x} : nat := match ...`

Does that make sense?

---

<div class="post-metadata">

**Author:** ![gert-smolka](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/gert-smolka/32/20_2.png) [@gert-smolka](https://discourse.rocq-prover.org/u/gert-smolka)\
**Post date:** [May 24, 2019, 9:47am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302/3 "2019-05-24T09:47:40Z")

</div>

Implementation-wise it does. But it implements a conversion rule, AFAICS.

---

<div class="post-metadata">

**Author:** ![gert-smolka](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/gert-smolka/32/20_2.png) [@gert-smolka](https://discourse.rocq-prover.org/u/gert-smolka)\
**Post date:** [May 24, 2019, 10:11am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302/4 "2019-05-24T10:11:40Z")

</div>

Ok, I see. That fix always ends after the recursive argument and the printer always merges the following lambdas into the fix explains it all. Thanks.

---

<div class="post-metadata">

**Author:** ![SkySkimmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/skyskimmer/32/369_2.png) [@SkySkimmer](https://discourse.rocq-prover.org/u/SkySkimmer)\
**Post date:** [May 24, 2019, 11:10am UTC](https://discourse.rocq-prover.org/t/fix-followed-by-fun/302/5 "2019-05-24T11:10:55Z")

</div>

yes‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮‮
