Skip to content

Commit a281cb8

Browse files
committed
doc signature constraints
1 parent d930521 commit a281cb8

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

doc/Language/variables.pod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ documentation in L<List>.
1616
1717
=begin table
1818
19-
Sigil Type constraint Default type Flattens Assignment
20-
===== =============== ============ ======== ==========
21-
$ Mu (no type constraint) Any No item
22-
& Callable Callable No item
23-
@ Positional Array Yes list
24-
% Associative Hash Yes list
19+
Sigil Type constraint Default type Flattens Assignment
20+
===== =============== ============ ======== ==========
21+
$ Mu (no type constraint) Any No item
22+
& L<Callable|/type/Callable> Callable No item
23+
@ Positional Array Yes list
24+
% Associative Hash Yes list
2525
2626
=end table
2727

doc/Type/Callable.pod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
Role for objects which support calling them. It's used in L<Block>,
1010
L<Routine>, L<Sub>, L<Method>, L<Submethod> and L<Macro> types.
1111
12+
Callables can be stored in C<&>-sigiled containers, the default type constrain
13+
if such a container is C<Callable>. A signature object can be used to
14+
force a check against the signature of the Callable to be stored into the
15+
congtainer.
16+
17+
my &a = {};
18+
my &b = -> {};
19+
my &c = sub () {};
20+
sub foo () {};
21+
my &d = &foo;
22+
my &f:(Int) = sub bar (Int) {};
23+
my &f:(Str) = -> Str {};
24+
1225
=head1 Methods
1326
1427
=head2 method assuming

doc/Type/Signature.pod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ my $sig = B<:($a, $b)>;
3838
# ^^^^^^^^ Standalone Signature object
3939
=end code
4040
41+
Signature literals can be used to define the signature of a callback or a
42+
cloasure.
43+
44+
sub f(&c:(Int)){}
45+
sub will-work(Int){}
46+
sub won't-work(Str){}
47+
f(&will-work);
48+
f(&wont-work); # fails at runtime
49+
f(-> Int { 'this works too' } );
50+
4151
=head2 Parameter Separators
4252
4353
A signature consists of zero or more I<L<parameters|Parameter>>, separated by comma.

0 commit comments

Comments
 (0)