Skip to content

Commit d658a1b

Browse files
committed
Added documetation on function return types.
1 parent cd879ef commit d658a1b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/Language/functions.pod6

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ values.
174174
put b.perl;
175175
# OUTPUT«\("a", "b", "c")␤»
176176
177+
=head2 Return Type Constraints
178+
179+
Perl 6 has many ways to specify a function's return type:
180+
181+
sub foo(--> Int) {}; say &foo.returns # (Int)
182+
sub foo() returns Int {}; say &foo.returns # (Int)
183+
sub foo() of Int {}; say &foo.returns # (Int)
184+
my Int sub foo() {}; say &foo.returns # (Int)
185+
186+
Attempting to return values of another type will cause a compilation error.
187+
188+
sub foo() returns Int { "a"; }; foo; # Type check fails
189+
177190
=head2 X<Multi-dispatch|declarator,multi>
178191
179192
Perl 6 allows you to write several routines with the same name, but different

0 commit comments

Comments
 (0)