[swift-evolution] [Review] SE-0023 API Design Guidelines

Dave Abrahams dabrahams at apple.com
Tue Jan 26 13:02:18 CST 2016


on Sun Jan 24 2016, Thorsten Seitz <swift-evolution at swift.org> wrote:

> Yes, I think they are a lot like sum (or union) types. In Ceylon enums
> actually are modeled as union types (there is no specific enum
> syntax).

Enums in Swift are exactly that; Ceylon chose the name "union;" we chose
"enum."  But Trent is saying that enum *cases* are like types.

> -Thorsten
>
>> Am 23.01.2016 um 19:57 schrieb Trent Nadeau via swift-evolution
>> <swift-evolution at swift.org>:
>> 
>> While enum cases may not be types from a compiler perspective, I think they are from a user's level.
>> 
>> Consider:
>> 
>> enum MyError: ErrorType {
>>     case FileError(fileName: String)
>>     case SocketError(ipAddr: String, port: Int16)
>> }
>> 
>> From a compiler perspective, it's a tagged union (one type), but for
>> a user this is a set of disjoint types that happen to share the same
>> space and have exhaustiveness checking, etc. It's a much more
>> efficient and convenient version of multiple structs or tuples.
>> 
>> On Sat, Jan 23, 2016 at 1:49 PM, Joe Groff
>> <jgroff at apple.com
>> <mailto:jgroff at apple.com>> wrote:
>> 
>> > On Jan 23, 2016, at 10:24 AM, Trent Nadeau
>> > <tanadeau at gmail.com
>> > <mailto:tanadeau at gmail.com>> wrote:
>> >
>> > I think it makes sense for enum cases to be UpperCamelCase as they
>> > can be thought of as scoped types (singleton types in the case of
>> > cases with no associated types).
>> 
>> They aren't, though. I don't see much value in setting false expectations.
>> 
>> -Joe
>> 
>> 
>> 
>> 
>> -- 
>> Trent Nadeau
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
-Dave



More information about the swift-evolution mailing list