Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Enumeration must DIE...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 59 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Som Snytt  
View profile  
 More options Oct 19 2012, 8:00 pm
From: Som Snytt <som.sn...@gmail.com>
Date: Fri, 19 Oct 2012 17:00:29 -0700
Local: Fri, Oct 19 2012 8:00 pm
Subject: Enumeration must DIE...

...where DIE = Divergent Implicit Expansion.

While looking at the DIE issue with mapping Enumeration values
https://issues.scala-lang.org/browse/SI-5534

I noticed that one quick fix is to make Value no longer Ordered.

My question is whether the "id" or "ordinal" for Enumeration.Values should
be internal detail.  By extension, we can remove Ordered.  I moved the
Ordering[Value] to a related companion class.

As an example, Reporter.Severity is a Value used just as an int wrapper. I
had to add Ordered back to Severity for INFO < ERROR tests.

I reread the DIE page of the spec, combed through the -Yinfer-debug, and
more/less understand what's intended by the newCBF for SortedSet.  However,
my understanding is only 66% so far on the implicit problem, so I don't
want to suggest that this is the optimal fix.

Also of interest, ValueSet uses an underlying BitSet, so you lose a bit of
range:
https://issues.scala-lang.org/browse/SI-6094
but probably ValueSet doesn't want to create sparse BitSets with huge
ranges anyway and should switch to a different representation after a
relatively small topId - bottomId.

If ids were only ordinals, with bottomId always zero, the conceptual model
would be as simple as it really is.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 20 2012, 6:03 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sat, 20 Oct 2012 15:03:11 -0700 (PDT)
Local: Sat, Oct 20 2012 6:03 pm
Subject: Re: Enumeration must DIE...

scala.Enumerations have caused nothing but trouble as far as I can think
back ... I wonder when it is finally enough and Scala will just use the
JVM's/Java's enums. Maybe macros will get us a lot closer to some sane,
interoperable solution by synthesizing the appropriate methods, just like
javac does.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Som Snytt  
View profile  
 More options Oct 20 2012, 10:51 pm
From: Som Snytt <som.sn...@gmail.com>
Date: Sat, 20 Oct 2012 19:51:13 -0700
Local: Sat, Oct 20 2012 10:51 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sat, Oct 20, 2012 at 3:03 PM, Simon Ochsenreither <

simon.ochsenreit...@gmail.com> wrote:
> scala.Enumerations have caused nothing but trouble as far as I can think
> back ... I wonder when it is finally enough and Scala will just use the
> JVM's/Java's enums. Maybe macros will get us a lot closer to some sane,
> interoperable solution by synthesizing the appropriate methods, just like
> javac does.

I should add that while I understand this point of view, in the subject
line I was only being flippant (which I hope has nothing to do with
flipping off, but one can't be sure about French terms).  Or maybe the word
is glib.  Let's say, flib, which is a flub that went over the top.

I actually like Enumeration as a showcase module.
http://www.artima.com/pins1ed/abstract-members.html#20.8

It's been hard to get exactly right, but only in a good way.  The last
issue was, "Enum doesn't know how to compare two ints."  Enumeration really
deserves its own section on Scala Puzzlers.  As the other thread on enums
and case objects shows, there should be a whole other section on enum
alternatives.

I was kind of surprised that paulp hasn't taken a big hammer to
Enumeration, but I just checked the history and there's a "Fix for
Enumeration" followed shortly thereafter by a 'Revert "Fix for
Enumeration".'   Just because a task is difficult and thankless, doesn't
mean it's not worth trying.

In the current issue, the set of values became a sorted set, and the code
was made to imitate BitSet (which it happens to use under the hood).
BitSet works nicely as a SortedSet[Int], but ValueSet as SortedSet[Value]
demonstrates this glitch.  (Because Value is Ordered, and Pair[Ordered, _]
picks up the implicit that seems to DIE.)

For me, the motivation is to understand implicits, the Ordering apparatus,
and how to extend collections.  I think that may rate a puzzler.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Oct 21 2012, 4:10 am
From: martin odersky <martin.oder...@epfl.ch>
Date: Sun, 21 Oct 2012 10:10:18 +0200
Local: Sun, Oct 21 2012 4:10 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 12:03 AM, Simon Ochsenreither <

simon.ochsenreit...@gmail.com> wrote:
> scala.Enumerations have caused nothing but trouble as far as I can think
> back ... I wonder when it is finally enough and Scala will just use the
> JVM's/Java's enums. Maybe macros will get us a lot closer to some sane,
> interoperable solution by synthesizing the appropriate methods, just like
> javac does.

You can use Java enums. But Scala will never have them.

I have to repeat my mantra once more here: My intention is to make Scala a
simpler language, with fewer features, not more. Most of the discussion on
the Scala lists goes the other way, where everyone is rooting for just one
more essential feature. That's only natural. But I have by now developed a
high level of resistance to most of these proposals.

Cheers

 - Martin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 11:15 am
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 08:15:58 -0700 (PDT)
Local: Sun, Oct 21 2012 11:15 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

Hi Martin,

I think we are in perfect agreement on that!

I just assumed that Scala absolutely needed some native, Java-enum-like
replacement. If that's not the case and using Java for this purpose is
considered fine, forget about my considerations on how to implement
Java-compatible enums in Scala without introducing new features.

Let's deprecate scala.Enumeration in 2.11 and guide people either towards
Java's enums or Scala's ADT-like approach.

One feature less, less bugs, less confusion on what to use (see
https://groups.google.com/d/topic/scala-user/2g-qzsfE0Us/discussion,
https://groups.google.com/d/topic/scala-user/2ZiLW92ieq4/discussion),
better interop and no need to duplicate APIs for Java/Scala enums.
(Considering the usage on scala.Enumeration in the wild, it seems people
already voted with their feet, too.)

Thanks and bye,

Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Phillips  
View profile  
 More options Oct 21 2012, 11:16 am
From: Paul Phillips <pa...@improving.org>
Date: Sun, 21 Oct 2012 08:16:03 -0700
Local: Sun, Oct 21 2012 11:16 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 1:10 AM, martin odersky <martin.oder...@epfl.ch>wrote:

> I have to repeat my mantra once more here: My intention is to make Scala a
> simpler language, with fewer features, not more. Most of the discussion on
> the Scala lists goes the other way, where everyone is rooting for just one
> more essential feature. That's only natural. But I have by now developed a
> high level of resistance to most of these proposals.

This seems like a questionable example of people rooting for one more
feature; the primary thing being rooted for when it comes to
scala.Enumeration is its removal. I thought leveraging java's existing and
satisfactory solutions where possible was scala's thing.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ismael Juma  
View profile  
 More options Oct 21 2012, 12:02 pm
From: Ismael Juma <ism...@juma.me.uk>
Date: Sun, 21 Oct 2012 17:01:59 +0100
Local: Sun, Oct 21 2012 12:01 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 4:16 PM, Paul Phillips <pa...@improving.org> wrote:
> This seems like a questionable example of people rooting for one more
> feature; the primary thing being rooted for when it comes to
> scala.Enumeration is its removal. I thought leveraging java's existing and
> satisfactory solutions where possible was scala's thing.

Particularly since 2.10 is meant to include exhaustiveness checks for Java
enums too.

Best,
Ismael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Oct 21 2012, 3:06 pm
From: martin odersky <martin.oder...@epfl.ch>
Date: Sun, 21 Oct 2012 21:05:45 +0200
Local: Sun, Oct 21 2012 3:05 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

I think Enumeration works fine for what it's supposed to do: Provide
enumerations without the overhead of one class per value. It beats the
alternative of defining numeric constants, for sure.

Cheers

 - Martin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Phillips  
View profile  
 More options Oct 21 2012, 3:09 pm
From: Paul Phillips <pa...@improving.org>
Date: Sun, 21 Oct 2012 12:09:41 -0700
Local: Sun, Oct 21 2012 3:09 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 12:05 PM, martin odersky <martin.oder...@epfl.ch>wrote:

> Provide enumerations without the overhead of one class per value.

Two classes per value, usually, not that case objects are the only
imaginable alternative.  But "works fine" is one of those subjective
things.  I like my scala features to work at least as well as the java
feature they are reimplementing.  By that standard it does not rise to the
level of fine.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Oct 21 2012, 3:11 pm
From: martin odersky <martin.oder...@epfl.ch>
Date: Sun, 21 Oct 2012 21:11:24 +0200
Local: Sun, Oct 21 2012 3:11 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 9:09 PM, Paul Phillips <pa...@improving.org> wrote:

> On Sun, Oct 21, 2012 at 12:05 PM, martin odersky <martin.oder...@epfl.ch>wrote:

>> Provide enumerations without the overhead of one class per value.

> Two classes per value, usually, not that case objects are the only
> imaginable alternative.  But "works fine" is one of those subjective
> things.  I like my scala features to work at least as well as the java
> feature they are reimplementing.  By that standard it does not rise to the
> level of fine.

> Yes, but it also has a whole lot less language footprint (to be exact:

zero). Enumerations in Java are quite enormous, similar in complexity to,
say, traits in Scala.  Is the convenience really worth it?

Cheers

 - Martin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 3:32 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 12:32:42 -0700 (PDT)
Local: Sun, Oct 21 2012 3:32 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

> Enumerations in Java are quite enormous, similar in complexity to, say,
> traits in Scala.  Is the convenience really worth it?

As far as I have understood it, people in this thread are arguing to get
rid of scala's bug-ridden, non-interoperable implementation in favor of
just using Java's enums, not about changing Scala-the-language to add
anything to it.

The convenience of not having to deal with scala.Enumeration and the poor
souls who fell into the trap using it has no impact on the language
footprint, but imho a lot of positive impact on people learning Scala.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rex Kerr  
View profile  
 More options Oct 21 2012, 4:11 pm
From: Rex Kerr <icho...@gmail.com>
Date: Sun, 21 Oct 2012 16:11:15 -0400
Local: Sun, Oct 21 2012 4:11 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 3:05 PM, martin odersky <martin.oder...@epfl.ch>wrote:

> I think Enumeration works fine for what it's supposed to do: Provide
> enumerations without the overhead of one

class per value. It beats the alternative of defining numeric constants,

> for sure.

Well, occasionally I suppose it does.  It's integer-only (numeric constants
are not), boxed (numeric constants are not), and allows (at compile-time)
but breaks on repeated values (numeric constants allow repeats and do not
break):

    object Wrong extends Enumeration { val a,b = Value(2) }

It can't check for complete pattern matches (unlike the case where classes
are used), and admits various weird usages that fail at runtime:

    object Okay extends Enumeration { val c = Value }
    object Uhoh extends Enumeration { val d = Okay.Value }

And although it doesn't add to the _language_ complexity, it does add to
the _library_ complexity.  It's amazing that it works at all, but even so
it doesn't work very well.

In practice, between needing byte and short and floating point constants,
and needing pattern matching, and needing bitmasks for which Enumeration
generates the wrong progression, I hardly use it at all.

I would use it more if it was something like

class Incrementable[T](val zero: T, val inc: T => T) {}
abstract class Enumeration[T: Incrementable] { ... }

  --Rex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Osheim  
View profile  
 More options Oct 21 2012, 4:18 pm
From: Erik Osheim <e...@plastic-idolatry.com>
Date: Sun, 21 Oct 2012 16:18:25 -0400
Local: Sun, Oct 21 2012 4:18 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 04:11:15PM -0400, Rex Kerr wrote:
> In practice, between needing byte and short and floating point constants,
> and needing pattern matching, and needing bitmasks for which Enumeration
> generates the wrong progression, I hardly use it at all.

Yeah, that's been my experience as well. Ugly-but-verbose numeric
constants are reliable, represent the (unboxed) values and types I
need, and be be easily inlined if that's what I want.

-- Erik


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
martin odersky  
View profile  
 More options Oct 21 2012, 4:22 pm
From: martin odersky <martin.oder...@epfl.ch>
Date: Sun, 21 Oct 2012 22:22:26 +0200
Local: Sun, Oct 21 2012 4:22 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

Enumeration comes with a usage pattern. If you use it wrongly, it breaks. I
do not see much that's wrong with that. If you use the wrong numeric
constants (ie the same one twice) your program will break as well. And that
is usually harder to guard against than just writing

  val a, b, c = Value

To each their own. People who do not like enumeration do not need to use
it. Sometimes numeric constants are better. But if you do not want to watch
out for duplicate values manually,
and you do not need utmost performance, enumerations are nice.

Cheers

 - Martin

> And although it doesn't add to the _language_ complexity, it does add to
> the _library_ complexity.  It's amazing that it works at all, but even so
> it doesn't work very well.

> In practice, between needing byte and short and floating point constants,
> and needing pattern matching, and needing bitmasks for which Enumeration
> generates the wrong progression, I hardly use it at all.

> I would use it more if it was something like

> class Incrementable[T](val zero: T, val inc: T => T) {}
> abstract class Enumeration[T: Incrementable] { ... }

Note that java enums only map to ints as well.

But to

>   --Rex

--
Martin Odersky
Prof., EPFL <http://www.epfl.ch> and Chairman, Typesafe<http://www.typesafe.com>
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 5:38 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 14:38:51 -0700 (PDT)
Local: Sun, Oct 21 2012 5:38 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

Hi,

Enumeration comes with a usage pattern. If you use it wrongly, it breaks. I

> do not see much that's wrong with that.

I honestly can't remember scala.Enumeration's "right" usage without looking
it every time I considered using it. That alones leaves a very bad taste.
Java managed to completely prevent this problem of "wrong usage patterns".
To this day, I haven't seen a definition of Java's enum which both compiled
_and_ broke at runtime.
Why would we consider less than this acceptable for Scala?

If you use the wrong numeric constants (ie the same one twice) your program

> will break as well. And that is usually harder to guard against than just
> writing

The issue, as far as I have understood it, is that people actually choose
to go back to some less expressive and less semantically exact code instead
of using Scala's Enumeration.
The only "static final int"s I see in Java are pre-enums. It seems that
Scala's Enumeration didn't even manage to solve this basic requirement in a
way people would actually want to use it.

To each their own. People who do not like enumeration do not need to use

> it.

Sometimes numeric constants are better. But if you do not want to watch out
> for duplicate values manually,

and you do not need utmost performance, enumerations are nice.

With type aliases and value types there are even more options for safe,
declarative code, but I think that's besides the point.
scala.Enumerations doesn't seem to solve any actual issue and has all the
drawbacks of not being a java.lang.Enum (like in annotations).
People who want to use enumerations should use Java enums, they don't
deserve that we waste their time with scala.Enumeration. So can we get rid
of scala.Enumeration, please?

Thanks and bye,

Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rex Kerr  
View profile  
 More options Oct 21 2012, 5:44 pm
From: Rex Kerr <icho...@gmail.com>
Date: Sun, 21 Oct 2012 17:44:20 -0400
Local: Sun, Oct 21 2012 5:44 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 5:38 PM, Simon Ochsenreither <

Can we try rewriting it first, taking advantage of the huge increase in
experience with writing reliable Scala library code and experience with the
difficulties of the existing version?

Or maybe wait until we have a proper units system--if we're going to get
one--so that we can leverage that for type-safety?

  --Rex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 6:04 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 15:04:29 -0700 (PDT)
Local: Sun, Oct 21 2012 6:04 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

> Can we try rewriting it first, taking advantage of the huge increase in
> experience with writing reliable Scala library code and experience with the
> difficulties of the existing version?

That's what I proposed in the first comment, but that was shot down. Also,
I don't see how we could make scala.Enumeration a Java enum without tons of
macro magic. In the end, it would be more like some Scala-like DSL where
the macro would completely rewrite the tree of the "enum declaration". This
couldn't be done with method-level macros, we would probably need macro
types or macro annotations for that.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rex Kerr  
View profile  
 More options Oct 21 2012, 6:26 pm
From: Rex Kerr <icho...@gmail.com>
Date: Sun, 21 Oct 2012 18:26:06 -0400
Local: Sun, Oct 21 2012 6:26 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

Well, you proposed a specific rewrite for it, which was basically to use
macros to mimic Java enums, which was shot down.  Even without going that
far, one could make some significant improvements--not to Java interop, but
to robustness, flexibility, speed, etc. (not all at once--one would need to
decide what to target).

  --Rex

On Sun, Oct 21, 2012 at 6:04 PM, Simon Ochsenreither <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 6:56 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 15:56:10 -0700 (PDT)
Local: Sun, Oct 21 2012 6:56 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

If the rewritten scala.Enumeration isn't compatible with Java enums, why
even bother rewriting it? I prefer a useless implementation with known bugs
to a useless implementation with unknown bugs.
There is a reason why practically no-one uses scala.Enumeration and
"incompatible with the platform' idea of enums" and "buggy" rank pretty
high on my list of suspects.

Nothing against a bit of NIH, but there is only one valid definition of
"enum" and that's the one of the JVM. If the JVM tells me "no, that's not
an enum, I won't allow you to use this in an annotation" I don't care about
Scala's reason for failing to work as expected.

Thanks and bye,

Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rex Kerr  
View profile  
 More options Oct 21 2012, 7:34 pm
From: Rex Kerr <icho...@gmail.com>
Date: Sun, 21 Oct 2012 19:34:17 -0400
Local: Sun, Oct 21 2012 7:34 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 6:56 PM, Simon Ochsenreither <

simon.ochsenreit...@gmail.com> wrote:
> If the rewritten scala.Enumeration isn't compatible with Java enums, why
> even bother rewriting it? I prefer a useless implementation with known bugs
> to a useless implementation with unknown bugs.
> There is a reason why practically no-one uses scala.Enumeration and
> "incompatible with the platform' idea of enums" and "buggy" rank pretty
> high on my list of suspects.

So you don't think it's possible to write less buggy/non buggy code?  Why
write anything?

Okay, so, kind of a straw man--I take it that you mean that platform
compatibility is an essential requirement for you.

> Nothing against a bit of NIH, but there is only one valid definition of
> "enum" and that's the one of the JVM. If the JVM tells me "no, that's not
> an enum, I won't allow you to use this in an annotation" I don't care about
> Scala's reason for failing to work as expected.

Reinforced by this point.  If you want Java enums, using Java is a pretty
sensible option.  But I don't personally miss being able to stick a Scala
Enumeration in a Java annotation.  >90% of my use cases is not creating new
annotations.  Unsafe numbering, namespace pollution, ints-only (see classic
java "Planets" example for what you can't do in Scala), etc. each chip off
a big fraction for me.  I'd be happy to have something better (c.f. "The
great is the enemy of the good.").

  --Rex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Ochsenreither  
View profile  
 More options Oct 21 2012, 8:09 pm
From: Simon Ochsenreither <simon.ochsenreit...@gmail.com>
Date: Sun, 21 Oct 2012 17:09:12 -0700 (PDT)
Local: Sun, Oct 21 2012 8:09 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

> If the rewritten scala.Enumeration isn't compatible with Java enums, why
>> even bother rewriting it? I prefer a useless implementation with known bugs
>> to a useless implementation with unknown bugs.
>> There is a reason why practically no-one uses scala.Enumeration and
>> "incompatible with the platform' idea of enums" and "buggy" rank pretty
>> high on my list of suspects.

> So you don't think it's possible to write less buggy/non buggy code?  Why
> write anything?

My point is that given the constraints it is obvious (imho) that
scala.Enumeration can't be fixed to justify its existence, not even
remotely.

> Okay, so, kind of a straw man--I take it that you mean that platform
> compatibility is an essential requirement for you.

What's the value added by not being compatible with the platform's idea of
enums?

> Nothing against a bit of NIH, but there is only one valid definition of
>> "enum" and that's the one of the JVM. If the JVM tells me "no, that's not
>> an enum, I won't allow you to use this in an annotation" I don't care about
>> Scala's reason for failing to work as expected.

> Reinforced by this point.  If you want Java enums, using Java is a pretty
> sensible option.  But I don't personally miss being able to stick a Scala
> Enumeration in a Java annotation.  >90% of my use cases is not creating new
> annotations.

I certainly don't miss scala.Enumeration. It does neither anything well nor
anything better than Java enums. It's usage is non-obvious and confusing.

Unsafe numbering, namespace pollution, ints-only (see classic java

> "Planets" example for what you can't do in Scala), etc. each chip off a big
> fraction for me.  I'd be happy to have something better (c.f. "The great is
> the enemy of the good.").

Which of these points is not already adressed by Java enums? How is some,
potentially future version of scala.Enumeration improving on what Java's
enum did reliably and painfree for the last 8 years? Why or who would want
to wait for it at all?
I think the fact that people abandoned scala.Enumeration in favor of
integers and fields speaks lengths about the situation. Why not put an end
to this suffering, get rid of Scala.Enumeration and give an official
blessing to Java enums?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Phillips  
View profile  
 More options Oct 21 2012, 9:26 pm
From: Paul Phillips <pa...@improving.org>
Date: Sun, 21 Oct 2012 18:26:23 -0700
Local: Sun, Oct 21 2012 9:26 pm
Subject: Re: [scala-internals] Re: Enumeration must DIE...

On Sun, Oct 21, 2012 at 4:34 PM, Rex Kerr <icho...@gmail.com> wrote:
> Unsafe numbering, namespace pollution, ints-only

Every scala.Enumeration value having the same erasure, which for most
people is a discovery not to be made until after they've boxed themselves
in.

scala> object Foo extends scala.Enumeration { val A, B, C = Value }
defined module Foo

scala> object Bar extends scala.Enumeration { val A, B, C = Value }
defined module Bar

scala> def f(x: Foo.Value) = 1 ; def f(x: Bar.Value) = 1
<console>:9: error: double definition:
method f:(x: Bar.Value)Int and
method f:(x: Foo.Value)Int at line 9
have same type after erasure: (x: Enumeration#Value)Int
       def f(x: Foo.Value) = 1 ; def f(x: Bar.Value) = 1
                                     ^


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oleg Galako  
View profile  
 More options Oct 22 2012, 2:18 am
From: Oleg Galako <ojo...@gmail.com>
Date: Sun, 21 Oct 2012 23:18:29 -0700 (PDT)
Local: Mon, Oct 22 2012 2:18 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

I think the answer to this will one day come as an independent library
(maybe using macros) which will be used by the community. Something like
Akka for actors.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan Vanek  
View profile  
 More options Oct 22 2012, 5:33 am
From: Jan Vanek <j3va...@gmail.com>
Date: Mon, 22 Oct 2012 11:32:58 +0200
Local: Mon, Oct 22 2012 5:32 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

In our project we need to translate the enums - provide texts for the
values. In Java what we have to do is to add an extra line into enums,
like:

public enum AddressStatus implements EnumClass<AddressStatus>
{
    ...
    public static final EnumMetaClass<AddressStatus> meta =
EnumMetaClass.create(AddressStatus.class, "i18n.app");

}

This is something what can be done much better in Scala. You can't easily
add functionality to Java enums. So, to say "just use Java enums" is not a
good solution.

Second, we need to customize the enumerated value (add fields, not just one
string). This is something you can't do with scala.enum, but with java enum
you at least have to write the fields + constructor (assign fields). In
Scala this would look nicer.

Third, we don't need complex numbering, built-in ordinal as in Java enum is
just fine. Rest is done with fields - constructor params.

So, I took the enum from V. Klang and adapted it to our needs. I think, in
the meantime, there exist dozens of house-local enums out there.

My point is, I think there is a need for Scala enum, just not the current
one. I mean enum as library, not language built-in.

Regards,
Jan

On Mon, Oct 22, 2012 at 2:09 AM, Simon Ochsenreither <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Suereth  
View profile  
 More options Oct 22 2012, 5:39 am
From: Josh Suereth <joshua.suer...@gmail.com>
Date: Mon, 22 Oct 2012 05:39:38 -0400
Local: Mon, Oct 22 2012 5:39 am
Subject: Re: [scala-internals] Re: Enumeration must DIE...

I'd like to chime in on the anti- scala.Enumeration camp.

My point is slightly altered from others:  scala.Enumeration doesn't feel
like it belongs in Scala.

If you look at all the other instances of "just a library" for scala, like
beakables, actors, futures then you see a nice, elegant abstraction that
solves a domain well, is performant at runtime, and "fits" into the
language as if it were native.

Enumeration is not.  If you look at its usage pattern it is different from
any other thing in the standard library, violates many of the common scala
idioms.   While enumerations tend to do this in any language, I think those
in Scala's library are a good idea gone poor.

I believe Viktor Klang had a toy replacement that was far more *runtime*
safe and performant and unified with case classes.  This I could get behind
as more "regular", adding features that feel more natural.   Placing a
sealed set of case objects in another object is not as foreign as calling a
`Value` method to create one or more instances.  During training we often
have to wave our hands here and encourage folks to investigate later.

Here's the crux of the complaint against Enumeration:

(1) toString is not the common way of pulling *data* out of an object (I.e.
the name member).
(2) Cannot easily extend enumerated type with additional members.  All new
behavior in the containing object.
(3) Implementation practically requires you to use it as top level object,
not inside a class or trait.
(4) Does not feel like a set of case object/classes, the major pattern in
scala used with pattern matching.

Basically, enumeration always feels like something unnatural, both as a
library in the standard, and something the language would support.

I don't even care about java interop here.   I'm not about to say we need
compiler support.   However I think the current library is lacking.   If
you would entertain improvements, I think we could make them.

If the main goal was avoiding more classes, then perhaps we've succeeded.
However, when I have an ich I want to scratch with enumeration, the current
library is a thorny branch, when I just want a nice stick.   I seriously
think we should consider improvement here.
On Oct 21, 2012 4:22 PM, "martin odersky" <martin.oder...@epfl.ch> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 59   Newer >
« Back to Discussions « Newer topic     Older topic »