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

Allow native-int enums as speculated by S12 #5299

Open
p6rt opened this issue May 6, 2016 · 5 comments
Open

Allow native-int enums as speculated by S12 #5299

p6rt opened this issue May 6, 2016 · 5 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented May 6, 2016

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

Searchable as RT128076$

@p6rt
Copy link
Author

p6rt commented May 6, 2016

From @titsuki

See the following results.

perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; my day $day = 0;'
Type check failed in assignment to $day; expected day but got Int (0)
  in block <unit> at -e line 1

The above behavior is different from the explanation of the spec page's one.
https://design.perl6.org/S12.html#Value_Generation

@p6rt
Copy link
Author

p6rt commented May 6, 2016

From @titsuki

P.S.

My Perl 6 version is

$ perl6 --version
This is Rakudo version 2016.04-99-g475063a built on MoarVM version 2016.04
implementing Perl 6.c.

On 2016-5月-05 木 18​:08​:19, cookbook_000@​yahoo.co.jp wrote​:

See the following results.

perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; my day $day = 0;'
Type check failed in assignment to $day; expected day but got Int (0)
in block <unit> at -e line 1

The above behavior is different from the explanation of the spec page's one.
https://design.perl6.org/S12.html#Value_Generation

@p6rt
Copy link
Author

p6rt commented May 6, 2016

From @smls

This doesn't look like a bug to me; just a case where ideas from the synopses did not make it into the language. The synopses are not the "spec", they are just design documents.

I also don't see how your assignment could work, considering how enums ended up behaving in Perl 6.c. As you can see from the output of the .^mro introspection method, your enum type inherits from Int, and not the other way around​:

  ➜ perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; say day.^mro'
  ((day) (Int) (Cool) (Any) (Mu))

A variable with a type constraint for a specific type, cannot be assigned a value of its *parent* type.

Furthermore, it looks to me like the example that you cite from S12, is meant to be about *native* types - i.e. "int" rather than "Int".
According to the ideas expressed there, an enum with a lowercase name would automatically be of that native "int" type, as if you had explicitly written​:

  ➜ perl6 -e 'my int enum day <Sun Mon Tue Wed Thu Fri Sat>;'

And then some magic could potentially happen with assignments.

Alas, native-typed enums apparently did not make it into Perl 6.c at all (the previous example fails with an internal error), and there are no tests related to them in the official test suite (which is the true "spec")​:
https://github.com/perl6/roast/tree/master/S12-enums
In any case, I have a feeling that some of the synopses were written at a time when native types were thought to be something slightly different than what they actually ended up being.

For these reasons, I changed the title of this issue to reflect that it is not a bug, but rather an idea that could potentially be investigated for future Perl 6.c versions.

@p6rt
Copy link
Author

p6rt commented May 6, 2016

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

@p6rt
Copy link
Author

p6rt commented May 7, 2016

From @titsuki

Thank you for your reply !

The synopses are not the "spec", they are just design documents.

I'll be careful to this point from now on.

On 2016-5月-06 金 05​:36​:34, smls75@​gmail.com wrote​:

This doesn't look like a bug to me; just a case where ideas from the
synopses did not make it into the language. The synopses are not the
"spec", they are just design documents.

I also don't see how your assignment could work, considering how enums
ended up behaving in Perl 6.c. As you can see from the output of the
.^mro introspection method, your enum type inherits from Int, and not
the other way around​:

➜ perl6 -e 'my Int enum day <Sun Mon Tue Wed Thu Fri Sat>; say
day.^mro'
((day) (Int) (Cool) (Any) (Mu))

A variable with a type constraint for a specific type, cannot be
assigned a value of its *parent* type.

Furthermore, it looks to me like the example that you cite from S12,
is meant to be about *native* types - i.e. "int" rather than "Int".
According to the ideas expressed there, an enum with a lowercase name
would automatically be of that native "int" type, as if you had
explicitly written​:

➜ perl6 -e 'my int enum day <Sun Mon Tue Wed Thu Fri Sat>;'

And then some magic could potentially happen with assignments.

Alas, native-typed enums apparently did not make it into Perl 6.c at
all (the previous example fails with an internal error), and there are
no tests related to them in the official test suite (which is the true
"spec")​:
https://github.com/perl6/roast/tree/master/S12-enums
In any case, I have a feeling that some of the synopses were written
at a time when native types were thought to be something slightly
different than what they actually ended up being.

For these reasons, I changed the title of this issue to reflect that
it is not a bug, but rather an idea that could potentially be
investigated for future Perl 6.c versions.

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

No branches or pull requests

1 participant