Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Special case allomorph coercion everywhere #6322

Open p6rt opened 7 years ago

p6rt commented 7 years ago

Migrated from rt.perl.org#131505 (status was 'open')

Searchable as RT131505$

p6rt commented 7 years ago

From @zoffixznet

(found in discussion in https://rt-archive.perl.org/perl6/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   \ rakudo-moar 7344a3​: OUTPUT​: «Str␤»   \<Zoffix__> m​: \<1>.Int.^name.say   \ 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>)   \ rakudo-moar 7344a3​: OUTPUT​: «IntStr␤»   \<Zoffix__> m​: -> Int() $_ { .^name.say }(\<1>)   \ 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.

p6rt commented 7 years ago

From @coke

On Sat, 03 Jun 2017 21​:20​:49 -0700, cpan@​zoffix.com wrote​:

(found in discussion in https://rt-archive.perl.org/perl6/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 \ rakudo-moar 7344a3​: OUTPUT​: «Str␤» \<Zoffix__> m​: \<1>.Int.^name.say \ 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>) \ rakudo-moar 7344a3​: OUTPUT​: «IntStr␤» \<Zoffix__> m​: -> Int() $_ { .^name.say }(\<1>) \ rakudo-moar 7344a3​: OUTPUT​: «IntStr␤»

So the question becomes​: do we special case allomorphs everywhere?

No. The current behavior seems correct to me.

- 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.

- 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

p6rt commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'