Comments (6)
Oh bat gizzards. That was written before ScalarEnum extended UnitEnum. We should unify the terminology one way or the other. What do we call non-scalar enums then if not unit enums? Or is unit enum still the correct term?
from enum-comparison.
AbstractEnum
being extended by UnitEnum and ScalarEnum is another option, if support for more immutable data types such as Distance::Miles(10) are added (Enum was your original proposal; that conflicted with the token)
The is_enum() function could alternately be reintroduced?
#43 is related
from enum-comparison.
Thinking on the Naming Things(tm) problem, there's two levels to consider.
The cases:
- Unit cases - no scalar.
- Scalar cases - scalar equivalent. May extend in the future to another enum?
- Tagged cases - with associated data.
The enum types:
- Unit Enum - Contains only unit cases.
- Scalar Enum - Contains only scalar cases.
- Tagged Enum - Contains only unit cases OR tagged cases.
cases()
makes sense on Unit Enum and Scalar Enum, but not on Tagged Enum, because tagged cases cannot be enumerated. So... whatever interfaces Tagged Enum ends up with cannot include cases()
.
Since scalar cases MAY extend in the future to non-scalars (although I don't quite grok that), maybe "Backed Enum"?
Breaking it up into tiny little bits:
interface NamedEnum {
public string $name;
}
interface EnumerableEnum {
public function cases();
}
interface BackedEnum {
public string $value;
public function from();
public function tryFrom();
}
// Today Unit Enum, can still use that name.
class Suit implements NamedEnum, EnumerableEnum {}
// Today Scalar Enum. We could call it Backed Enum, I guess?
class Size implements NamedEnum, EnumerableEnum, BackedEnum {}
// Future tagged cases
class Maybe implements NamedEnum {}
Thoughts?
from enum-comparison.
Hm, I think our current terminology is mostly fine, except for ScalarEnum
. BackedEnum
is fine by me although I'd still prefer ValueEnum
. If we call ADTs ADTs or tagged unions there should be no confusion. I don't think we actually need a NamedEnum
interface or an interface for ADTs (they have no special methods).
from enum-comparison.
Well, one thing that the above breakdown demonstrated to me is that perhaps the ScalarEnum interface should not extend UnitEnum. Or rather, UnitEnum isn't a thing; An enum is enumerable or not. cases() won't appear on ADTs/tagged enums. NamedEnum doesn't need to be a thing because there's no methods on it, but I think EnumerableEnum and BackedEnum/ValueEnum/whatever make more sense, especially when looking forward to Tagged Enums.
from enum-comparison.
Coming back to the original issue: How about changing the sentence to something like:
An enum that has a finite set of values enum is known as a “Unit Enum”. All of the enums proposed in this RFC are Unit Enums but this would change if algebraic data types are accepted into the language.
from enum-comparison.
Related Issues (20)
- value or value() or getValue()? HOT 4
- Tests for __CLASS__ and __FUNCTION__
- Namespace tests
- Constant expressions for primitive values? HOT 3
- Rename ScalarEnum to Raw- or ValueEnum? HOT 8
- Prevent offsetGet on enums in const expr HOT 14
- Clarify types of operations that are allowed in expressions in RFC document/implementation HOT 1
- Fast method to get only the name of a case? HOT 4
- Is the name ReflectionEnumCase(implementation) or ReflectionCase(RFC document) HOT 3
- ReflectionEnumConst for ADT compatibility HOT 3
- from/has scalar in reflection HOT 5
- Handle failure in from HOT 7
- Override getDeclaringClass() to return ReflectionEnum instead of getEnum() HOT 5
- has() vs tryFrom() HOT 7
- Inherited ReflectionEnum methods HOT 1
- Custom print_r output HOT 7
- I created an online WebAssembly demo for enums HOT 2
- Improve issue message for array unpacking of Traversable enum HOT 1
- Some feedback on Reddit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enum-comparison.