A Case Against Currying
4 hours ago
- #currying
- #partial application
- #functional programming
- Curried functions are a common feature in functional languages, allowing functions to be applied to arguments one at a time.
- Three styles of multi-parameter function definitions: imperative (parameter list), curried (functional), and tuple (single parameter with multiple values).
- Partial application is often cited as a benefit of curried functions, but it can also be achieved with other styles using syntactic sugar.
- Curried functions can lead to performance overhead due to intermediate function creation, though optimizers may mitigate this.
- Curried functions introduce asymmetry in function composition, making them less intuitive for functions with multiple outputs.
- Dependent function types in languages like Gallina or Agda benefit from the curried style due to type dependencies on input values.
- The article suggests considering tuple style for new functional languages or libraries, despite the elegance of curried functions.