OxL Reference

error bad-main

error Standard: [§2.4]

What it means#

fn main() is the entry point of the program: the runtime starts it as the startup task without arguments (§2.4). The Standard allows two forms only: fn main() and fn main() -> () | E, where every E is an error type (an error from main ends the process with code 1). Effects are not restricted. Parameters, generic parameters and a result with a value (-> i32, -> str | IoError, fn main() => 42) are reported.

Example#

oxl✓ checked in CI
fn main(args: List<str>) io {   // <- bad-main
  print("{args.len()} arguments")
}
error
bad-main

How to fix#

oxl✓ checked in CI
fn main() io {
  let args = std.os.args()
  print("{args.len()} arguments")
}

Read the command line with std.os.args() and the environment with std.os.env(name). To report a failure, return an error (fn main() -> () | Usage) instead of an exit code; to show a result, print it.

See also#

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides