Skip Menu |
Report information
Id: 131505
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cpan [at] zoffix.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [@LARRY] Special case allomorph coercion everywhere
Download (untitled) / with headers
text/plain 1.4k
(found in discussion in https://rt.perl.org/Ticket/Display.html?id=131493 ) We have some special casing for coercion of allomorphs in some instances, which is done so there'd be some way to force one of the two types to fall out of it, since we have types where to whom object identity matters a bunch: <Zoffix__> m: <1>.Str.^name.say <camelia> rakudo-moar 7344a3: OUTPUT: «Str␤» <Zoffix__> m: <1>.Int.^name.say <camelia> rakudo-moar 3755c0: OUTPUT: «Int␤» However, allomorphs don't get coerced with parameter coercers and possibly some other places. There's no special casing here done. The coercer coerces to Str type and IntStr allomorph is already it. <Zoffix__> m: -> Str() $_ { .^name.say }(<1>) <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr␤» <Zoffix__> m: -> Int() $_ { .^name.say }(<1>) <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr␤» So the question becomes: do we special case allomorphs everywhere? - If yes, any place we special case them will have a caveat and surprising behaviour where type don't get coerced to exact asked type if it's a subclass of it - If no, we get surprising special cased behaviour like above, but only in one case - Or we could remove the coercion to one of the two types and have <1>.Str return the same IntStr; in that case I'm unsure what would be a way to "collapse" an allomorph into numeric or string parts, since many ops use these methods to coerce stuff.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.8k
On Sat, 03 Jun 2017 21:20:49 -0700, cpan@zoffix.com wrote: Show quoted text
> (found in discussion in > https://rt.perl.org/Ticket/Display.html?id=131493 ) > > > We have some special casing for coercion of allomorphs in some > instances, which > is done so there'd be some way to force one of the two types to fall > out of it, > since we have types where to whom object identity matters a bunch: > > <Zoffix__> m: <1>.Str.^name.say > <camelia> rakudo-moar 7344a3: OUTPUT: «Str␤» > <Zoffix__> m: <1>.Int.^name.say > <camelia> rakudo-moar 3755c0: OUTPUT: «Int␤» > > However, allomorphs don't get coerced with parameter coercers and > possibly some > other places. There's no special casing here done. The coercer coerces > to Str type > and IntStr allomorph is already it. > > <Zoffix__> m: -> Str() $_ { .^name.say }(<1>) > <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr␤» > <Zoffix__> m: -> Int() $_ { .^name.say }(<1>) > <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr␤» > > > So the question becomes: do we special case allomorphs everywhere?
No. The current behavior seems correct to me. Show quoted text
> - If yes, any place we special case them will have a caveat and > surprising behaviour > where type don't get coerced to exact asked type if it's a > subclass of it
If you want something coerced to the exact type, this can be done outside of the signature. I would just document the behavior for coercions clearly, in that if the value already satisfy the type in the coercer, your value is passed through unchanged. Show quoted text
> - If no, we get surprising special cased behaviour like above, but > only in one case > - Or we could remove the coercion to one of the two types and have > <1>.Str return the same > IntStr; in that case I'm unsure what would be a way to "collapse" > an allomorph into > numeric or string parts, since many ops use these methods to coerce > stuff.
-- Will "Coke" Coleda


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org