Skip to content

Commit acc747f

Browse files
authored
Be more specific about coercion being a convention
1 parent a9f8526 commit acc747f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

S13-overloading.pod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ Note that the angle bracket subscripting form C<< .<a b c> >>
164164
automatically translates itself into a call to C< .{'a','b','c'} >,
165165
so defining methods for angles is basically useless.
166166

167-
The expected semantics of C<&.()> is that of a type coercion which may
167+
The expected semantics of C<&.()> is that of a type
168+
on which may
168169
or may not create a new object. So if you say:
169170

170171
$fido = Dog.new($spot)
@@ -181,8 +182,10 @@ do C<Dog.new($spot)> instead.
181182

182183
It is also possible (and often preferable) to specify coercions from
183184
the other end, that is, for a class to specify how to coerce one of
184-
its values to some other class. If you define a method whose name
185-
is a declared type, it is taken as a coercion to that type:
185+
its values to some other class. So, if you define a method whose name
186+
happens to be type name, you can view it as a coercion to that type. But that method
187+
is a regular method even its name happens to be a type name. That means the
188+
compiler does not enforce the type of the returned value.
186189

187190
method Str { self.makestringval() }
188191

0 commit comments

Comments
 (0)