Course of Raku / Advanced / Subroutines / More on MAIN subroutines / Exercises / A typed MAIN
Solution: A typed MAIN
Here is a possible solution to the task.
Code
sub MAIN(Int $n) {
say $n * 2;
}🦋 You can find the source code in the file typed-main.raku.
Output
$ raku typed-main.raku 5
10
$ raku typed-main.raku abc
Usage:
typed-main.raku <n>Comments
The
Intconstraint means the command-line word must look like an integer. Given5, it binds to$nand the body prints10.Given
abc, the value cannot become anInt, so the signature does not match. Raku does not run the body — it prints the generated usage message instead, giving you argument validation without any manual checks.