Variadic Functions in Idris
Here’s the example translated to Idris as requested.
Variadic functions can be called with any number of trailing arguments. Here’s an example that takes an arbitrary number of Int
s as arguments.
Here’s a function that will take an arbitrary number of Int
s as arguments.
Within the function, the type of nums
is equivalent to List Int
. We can iterate over it with functions like foldl
.
Variadic functions can be called in the usual way with individual arguments. If you already have multiple arguments in a list, you can directly pass it to the function.
To run the program, put the code in VariadicFunctions.idr
and use idris
to execute it:
Another key aspect of functions in Idris is their ability to form closures, which we’ll look at next.