Replies: 2 comments
-
From a reddit thread (you may need to expand comments):
Conclusions:
Edit: (18 July 2022) - renaming changes committed |
Beta Was this translation helpful? Give feedback.
-
Trying this again, from the top:The Ecstasy type algebra defines three operators:
But internally, there are actually five composite type concepts that result from these three operators:
Resulting state:
The anonymous pure type syntax is expected to be fairly uncommon. It will be primarily useful for defining delegation sub-sets. While rare, it is an important capability, and we believe that this syntax allows us to "square up" a missing corner of the type algebra, without polluting the general purpose type forms. Additionally, the terminology changes should help avoid some confusion, particular for anyone with existing knowledge of type theory applied in languages. |
Beta Was this translation helpful? Give feedback.
-
The Ecstasy type algebra defines three operators:
|
for "intersection type"+
for "union type"-
for "difference type"But internally, there are actually five composite type concepts that result from these three operators:
T1 | T2
usually means "either a T1 or a T2", but it can also mean "the traits shared by both the T1 and T2 types" (the "intersection" in set theory)T1 + T2
means "both a T1 and a T2", which is (for all practical purposes) the same as "the union of the traits in T1 with the traits in T2"T1 - T2
usually means "a T1 and not a T2", but it can also mean "the remaining traits after the set of traits in T2 are subtracted from from the set of traits in T1" (the "relative complement" or "set-theoretic difference" in set theory)In addition to the above, we had reserved an operator for the explicit "and-not" use case, and we planned to introduce a syntax for specifying difference types without a nominal type for the subtrahend.
Gene and I have a proposed set of changes that addresses all of the above:
|
type operator will define an either type.o
whose compile time type is known to beT1|T2
, the compile-time available traits ofo
are defined by the intersection of the set of traits fromT1
and the set of traits fromT2
.Int32-Unchecked
specifies anInt32
and not@Unchecked
.delegates
clause and theinto
clause. We decided to retain the "difference type" meaning when the-
operator is used to define a delegation type."{" traitspecifiers "}"
, wheretraitspecifiers
is a semicolon delimited/terminated list oftraitspecifier
, each of which is either a method/property name or a method/property signature. This syntax is permitted in specific constructs:typedef
statementdelegates
clauseinto
clause.is()
or.as()
expressionThis syntax is expected to be fairly uncommon. It will be primarily useful for defining delegation sub-sets. While rare, it is an important capability, and we believe that this syntax allows us to "square up" a missing corner of the type algebra, without polluting the general purpose type forms.
Additionally, the terminology changes should help avoid some confusion, particular for anyone with existing knowledge of type theory applied in languages using the terms difference type and/or intersection type. Ecstasy's conceptual types are based on set theory, and the use of the set theory terms we previously selected was based on actul set operations. Nonetheless, we expect that there may be some initial confusion for new developers about our use of the term union type, primarily because of the type-unsafe manner in which the term is abused in other languages (C/C++ for example). Specifically, our union type is actually a type formed from the union of two types. What some languages refer to as a tagged union (confusingly referred to as a sum type by at least one existing language) or a discriminated union, is actually equivalent to an Ecstasy either type, which as discussed above, further implies an intersection type.
Regardless, we gave up on using some terms because the confusion created wasn't worth it. For one example of the confusion, look no further than Wikipedia itself (emphasis added):
Beta Was this translation helpful? Give feedback.
All reactions