Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array[Int] ~~ Array[Numeric] is false #5544

Open
p6rt opened this issue Aug 7, 2016 · 4 comments
Open

Array[Int] ~~ Array[Numeric] is false #5544

p6rt opened this issue Aug 7, 2016 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 7, 2016

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

Searchable as RT128866$

@p6rt
Copy link
Author

p6rt commented Aug 7, 2016

From @LLFourn

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.

@p6rt
Copy link
Author

p6rt commented May 5, 2017

From @zoffixznet

On Sun, 07 Aug 2016 03​:51​:27 -0700, lloyd.fourn@​gmail.com wrote​:

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?

@p6rt
Copy link
Author

p6rt commented May 5, 2017

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

@p6rt
Copy link
Author

p6rt commented May 17, 2017

From @smls

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.

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant