Command Line Arguments in Idris
Command-line arguments are a common way to parameterize execution of programs. For example, idris hello.idr -o hello
uses hello.idr
and -o hello
arguments to the idris
program.
To experiment with command-line arguments, it’s best to compile the program first:
In Idris, we use the System
module to access command-line arguments. The getArgs
function returns a list of strings containing the program name and all command-line arguments.
Note that Idris uses index'
for safe indexing, which returns a Maybe
type. We’ve added a simple case expression to handle the possibility of not having enough arguments.
Next, we’ll look at more advanced command-line processing with options parsing libraries available in Idris.