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

Owner: Nobody
Requestors: lloyd.fourn [at] gmail.com
Cc:
AdminCc:

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



Date: Sun, 07 Aug 2016 10:50:58 +0000
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: [BUG] Array[Int] ~~ Array[Numeric] is false
To: "rakudobug [...] perl.org" <rakudobug [...] perl.org>
Download (untitled) / with headers
text/plain 215b
say Array[Int] ~~ Array[Int]; # True
say Array[Int] ~~ Positional[Numeric];  # True
say Positional[Int] ~~ Positional[Numeric]; # True
say Array[Int] ~~ Array[Numeric]; # False

The last one should be true as well.

RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.4k
On Sun, 07 Aug 2016 03:51:27 -0700, lloyd.fourn@gmail.com wrote: Show quoted text
> say Array[Int] ~~ Array[Int]; # True > say Array[Int] ~~ Positional[Numeric]; # True > say Positional[Int] ~~ Positional[Numeric]; # True > say Array[Int] ~~ Array[Numeric]; # False > > The last one should be true as well.
How come last one should be same? Aren't they different types? I'd expect `Array[Int] ~~ Positional[Numeric]` to give False Some investigation: ( https://irclog.perlgeek.de/perl6-dev/2017-05-05#i_14534952 ) IIRC calling a method on a role puns it and in fact punned Positional doesn't accept a Positional of a different type, but calling .ACCEPTS does not appear to pun a role: 00:58 Zoffix Calling a method on a role puns it, right? 00:58 m: say Positional[Numeric].ACCEPTS: Positional[Int] 00:58 camelia rakudo-moar f2af3d: OUTPUT: «True␤» 00:58 Zoffix m: say Positional[Numeric].^pun.ACCEPTS: Positional[Int] 00:58 camelia rakudo-moar f2af3d: OUTPUT: «False␤» 01:00 Zoffix m: say Positional[Numeric].self.ACCEPTS: Positional[Int] 01:00 camelia rakudo-moar f2af3d: OUTPUT: «False␤» Also, I don't know whether this is right or not; that `istype` op gives true when a role is parameterized with a type that accepts another... 01:01 Zoffix m: use nqp; dd nqp::istype(Positional[Int], Positional[Cool]) 01:01 camelia rakudo-moar f2af3d: OUTPUT: «1␤» 01:01 Zoffix Is it supposed to do that?
Download (untitled) / with headers
text/plain 971b
Show quoted text
> How come last one should be same? Aren't they different types? I'd expect `Array[Int] ~~ Positional[Numeric]` to give False
They are different types, but one could logically be considered a "subtype" of the other (and would be in some programming languages). E.g. in C#, a class Foo which takes a type parameter can define whether it wants to be, with regard to that parameter (using Perl 6 notation): covariant: Foo[Dog] ~~ Foo[Animal] contravariant: Foo[Animal] ~~ Foo[Dog] invariant: neither (Or at least that's how I understand it, I'm just starting to learn C#.) It appears that in Perl 6, currently only *Invariance* is supported for parameterized types. Whether that is a conscious design choice ("keeping it simple"), or something that might be extended in the future given sufficient demand/tuits, is something that jnthn should be able to answer, since if I'm not mistaken he's done much of the Perl 6 OO work and is also a C#/Java expert.


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