Anonymous Enums

Hi, I have a proposal.

enum Foo {
  case foo,bar
}

func test(a:Foo) {
  // …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
  // ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

My worry is that this isn’t very different from

enum Temperature { case low, normal, high }

It’s 7 more characters and fully expressible now.

- Harlan

···

On Feb 19, 2016, at 12:48 PM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:

I too very much like the cleverness of this, but in my experience often what is initially a single-use enum turns into a multi-use enum in short order, so I don’t know if I’d be able to use this much at the end of the day.

Gotta say I like that syntax, though. Could be neat as a shorthand for defining regular enum cases, maybe! :P

enum Temperature = [low | normal | high]

l8r
Sean

On Feb 19, 2016, at 2:42 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

It's certainly clever and I particularly like the temperature example.

-- E

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
case foo,bar
}

func test(a:Foo) {
// …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
// ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
// ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm against this.

In many cases, such 'one off' types are best expressed as nested types in some other type. I think we can get more mileage by fixing the cases where nested types are currently not supported, which would not require going through the evolution process, than adding new grammar to the language for yet another special case.

Slava

···

On Feb 19, 2016, at 8:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
  case foo,bar
}

func test(a:Foo) {
  // …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
  // ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

It's certainly clever and I particularly like the temperature example.

-- E

···

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
  case foo,bar
}

func test(a:Foo) {
  // …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
  // ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

That specific syntax would likely have issues conflicting with parsing collections, but if the idea is sound, a grammar can follow.

-- E
p.s. Also error enumerations would be nice

···

On Feb 19, 2016, at 1:48 PM, Sean Heber <sean@fifthace.com> wrote:

I too very much like the cleverness of this, but in my experience often what is initially a single-use enum turns into a multi-use enum in short order, so I don’t know if I’d be able to use this much at the end of the day.

Gotta say I like that syntax, though. Could be neat as a shorthand for defining regular enum cases, maybe! :P

enum Temperature = [low | normal | high]

l8r
Sean

On Feb 19, 2016, at 2:42 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

It's certainly clever and I particularly like the temperature example.

-- E

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
case foo,bar
}

func test(a:Foo) {
// …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
// ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
// ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

The proposed `func adjustTemperature(temp:[low|normal|high])` would likely have grammar issues.

-- E

···

On Feb 19, 2016, at 1:57 PM, Harlan Haskins <harlan@harlanhaskins.com> wrote:

My worry is that this isn’t very different from

enum Temperature { case low, normal, high }

It’s 7 more characters and fully expressible now.

- Harlan

On Feb 19, 2016, at 12:48 PM, Sean Heber via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I too very much like the cleverness of this, but in my experience often what is initially a single-use enum turns into a multi-use enum in short order, so I don’t know if I’d be able to use this much at the end of the day.

Gotta say I like that syntax, though. Could be neat as a shorthand for defining regular enum cases, maybe! :P

enum Temperature = [low | normal | high]

l8r
Sean

On Feb 19, 2016, at 2:42 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

It's certainly clever and I particularly like the temperature example.

-- E

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi, I have a proposal.

enum Foo {
case foo,bar
}

func test(a:Foo) {
// …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
// ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
// ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

I too very much like the cleverness of this, but in my experience often what is initially a single-use enum turns into a multi-use enum in short order, so I don’t know if I’d be able to use this much at the end of the day.

Gotta say I like that syntax, though. Could be neat as a shorthand for defining regular enum cases, maybe! :P

enum Temperature = [low | normal | high]

l8r
Sean

···

On Feb 19, 2016, at 2:42 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

It's certainly clever and I particularly like the temperature example.

-- E

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
  case foo,bar
}

func test(a:Foo) {
  // …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
  // ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Good point! I guess it’s not exactly a huge savings. :P I just liked the look of the syntax. :)

l8r
Sean

···

On Feb 19, 2016, at 2:57 PM, Harlan Haskins <harlan@harlanhaskins.com> wrote:

My worry is that this isn’t very different from

enum Temperature { case low, normal, high }

It’s 7 more characters and fully expressible now.

- Harlan

On Feb 19, 2016, at 12:48 PM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:

I too very much like the cleverness of this, but in my experience often what is initially a single-use enum turns into a multi-use enum in short order, so I don’t know if I’d be able to use this much at the end of the day.

Gotta say I like that syntax, though. Could be neat as a shorthand for defining regular enum cases, maybe! :P

enum Temperature = [low | normal | high]

l8r
Sean

On Feb 19, 2016, at 2:42 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

It's certainly clever and I particularly like the temperature example.

-- E

On Feb 19, 2016, at 9:46 AM, Yong hee Lee via swift-evolution <swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
case foo,bar
}

func test(a:Foo) {
// …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
// ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
// ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I don’t think I would use this often, but when I did use it, it would be
great. +1 from me.

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan&gt; |
jeffkelley.org

···

On Fri, Feb 19, 2016 at 11:46 AM, Yong hee Lee via swift-evolution < swift-evolution@swift.org> wrote:

Hi, I have a proposal.

enum Foo {
  case foo,bar
}

func test(a:Foo) {
  // …
}

test(.bar)

If I use an enum only as a parameter of a function, the name of enum is
redundant.

so I suggest a compact version like below.

func test(a:[foo|bar]) {
  // ...
}

test(.bar)

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

I think this is very useful.
What do you think?

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

func adjustTemperature(temp:[low|normal|high]) {
  // ...
}

adjustTemperature(.high)

This is clever, and I certainly understand the appeal, but sooner or later someone is going to want to store a value that's intended to go into this parameter in a variable, and then what do they do?

···

--
Brent Royal-Gordon
Architechies