CatalaLang / catala

Programming language for literate programming law specification
https://catala-lang.org
Apache License 2.0
1.96k stars 80 forks source link

Add a list folding surface syntax #647

Open denismerigoux opened 1 month ago

denismerigoux commented 1 month ago

Right now, many of our syntactic list manipulation operators are implemented underneath using fold. However, the user cannot directly write a fold in the Catala surface syntax. The CNAF expressed the need for such an operator to be exposed. As it is polymorphic, it will require special syntax.

The signature for this operator would be fold : 'a list -> ('b -> 'a -> 'b) -> 'b -> 'b.

AltGr commented 1 month ago

One possible syntax: Since we already have <foo(v)> for <v> among <list> for map one possibility would be to extend that with details: <foo(v,acc)> for <v> among <list> accumulating into <acc> starting from <init> (the starting could be removed for conciseness... maybe the into (or even the accumulating ?) as well ?)

E.g. Compute the sum of a list of money with:

x + y for x among revenues accumulating into y starting from $0