Skip to content

Commit 775c00f

Browse files
committed
fill in role in /language/typesystem
1 parent 56fc629 commit 775c00f

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

doc/Language/typesystem.pod6

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ L<X::Attribute::Required|/type/X::Attribute::Required>.
402402
CATCH { default { say .^name => .Str } }
403403
# OUTPUT«X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it.␤»
404404
405-
=head3 trait C<does>
406-
407-
TODO
408-
409405
=head3 trait C<hides>
410406
411407
TODO
@@ -442,6 +438,42 @@ C<.^ver> and C<^.auth>.
442438
443439
=head2 C<role>
444440
441+
Roles are class fragments, which allow the definition of interfaces that are
442+
shared by classes. The C<role> declarator also introduces a type object that
443+
can be used for type checks. Roles can be mixed into classes and objects at
444+
runtime and compile time. The C<role> declarator returns the created type
445+
object thus allowing the definition of anonymous roles and in-place mixins.
446+
447+
role Serialize {
448+
method to-string { self.Str }
449+
method to-number { self.Num }
450+
}
451+
452+
class A does Serialize {}
453+
class B does Serialize {}
454+
455+
my Serialize @list;
456+
@list.push: A.new;
457+
@list.push: B.new;
458+
459+
say @list».to-string;
460+
# OUTPUT«[A<57192848> B<57192880>]␤»
461+
462+
Use C<...> as the only element of a method body to declare a method to be
463+
abstract. Any class getting such a method mixed in has to overload it. If the
464+
method is not overloaded before the end of the compilation unit
465+
C<X::Comp::AdHoc> will be thrown.
466+
467+
EVAL 'role R { method overload-this(){...} }; class A does R {}; ';
468+
CATCH { default { say .^name, ' ', .Str } }
469+
# OUTPUT«X::Comp::AdHoc Method 'overload-this' must be implemented by A because it is required by a role␤»
470+
471+
=head3 trait C<does>
472+
473+
TODO
474+
475+
=head3 trait C<but>
476+
445477
TODO
446478
447479
=head3 Role Arguments

0 commit comments

Comments
 (0)