Skip to content

Instantly share code, notes, and snippets.

@iarna
Last active December 31, 2015 19:09
Show Gist options
  • Save iarna/8031884 to your computer and use it in GitHub Desktop.
Save iarna/8031884 to your computer and use it in GitHub Desktop.
Perl6 optional types
sub test(Int $a) { say $a + 3 }
test(23); # 26
sub test(Int $a) { say $a + 3 }
test("23"); # Calling 'test' will never work with argument types (str) (line 1)
            #    Expected: :(Int $a)
sub test(Int $a) { say $a + 3 }
my $b = "23";
test($b); # runtime error: Nominal type check failed for parameter '$a'; expected Int but got Str instead
sub test($a) { say $a + 3 }
test("23"); # 26
sub test(Int $a) { say $a + 3 }
my $b = "23";
test($b); # 26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment