Coder Social home page Coder Social logo

UnitEnum definition about enum-comparison HOT 6 CLOSED

iluuu1994 avatar iluuu1994 commented on June 16, 2024
UnitEnum definition

from enum-comparison.

Comments (6)

Crell avatar Crell commented on June 16, 2024

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.

TysonAndre avatar TysonAndre commented on June 16, 2024

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.

Crell avatar Crell commented on June 16, 2024

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.

iluuu1994 avatar iluuu1994 commented on June 16, 2024

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.

Crell avatar Crell commented on June 16, 2024

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.

iluuu1994 avatar iluuu1994 commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.