anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
453 stars 53 forks source link

Recursive lambdas #1638

Open jonaprieto opened 1 year ago

jonaprieto commented 1 year ago
f : {A : Type} -> List A -> Pair (List A) Nat;
f := go(acc1 := []; acc2 := 0)@\{
     []        := (acc1, acc2)
   | (x :: xs) := go (x :: acc1) (acc2 + 1) xs
  };
lukaszcz commented 1 year ago

As Jeremy pointed out, it would be more consistent to denote the multiple accumulator arguments as follows:

f : (A : Type) -> List A -> Pair (List A) Nat;
f := go(acc1 := [])(acc2 := 0)@\{
     []        := (acc1, acc2)
   | (x :: xs) := go (x :: acc1) (acc2 + 1) xs
  };

The ; does suggest a pair, which may be confusing.

We could also consider adding optional arguments in general. I opened an issue about them: #1991.