ch-systems / petr

the petr programming language -- Programmable Effects TRacking
https://playground.petr.sh
5 stars 0 forks source link

Partial Application/Currying/Anonymous Functions #23

Open sezna opened 2 months ago

sezna commented 2 months ago

If we get lambdas and anonymous functions, partial application can be syntactic sugar for those.

sezna commented 2 months ago

As of right now, the syntax and approach I like is to use underscores instead of expressions to denote an in-place lambda. E.g.,

func(a, b, _)

is shorthand for:

(x) => func(a, b, x)

I think there are some concrete advantages here versus Haskell/-like currying:

  1. Better looking types. A => a -> b -> c makes sense when you know what is going on, but it certainly isn't intuitive or particularly practical.
  2. Better type errors. With underscores, you can still throw "incorrect number of args" errors instead of a type error that involves a partially applied function, like Haskell.