You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Oct 25th 2017 | Split prefix types from [SIP33](http://docs.scala-lang.org/sips/priority-based-infix-type-precedence.html), and emphasize motivation |
17
+
| Nov 29th 2017 | Updated SIP according to feedback in the PR, and recent update to SIP23 |
17
18
18
19
19
20
Your feedback is welcome! If you're interested in discussing this proposal, head over to [this](https://contributors.scala-lang.org/t/sip-nn-make-infix-type-alias-precedence-like-expression-operator-precedence/471) Scala Contributors thread and let me know what you think.
Add support for prefix types, which is equivalent to the prefix operations for expressions.
59
-
60
-
```
61
-
PrefixType ::= [`-' | `+' | `~' | `!'] SimpleType
62
-
CompoundType ::= PrefixType
63
-
| AnnotType {with AnnotType} [Refinement]
64
-
| Refinement
65
-
```
66
-
67
-
---
68
-
69
58
## Motivation
70
-
Developers expect terms and types to be expressed the samefor mathematical and logical operations.
59
+
It is easier to reason about the language when mathematical and logical operations for both terms and types are expressed the same. The proposal is relevant solely for projects which utilize numeric literal type operations (supported by SIP23, which was not yet accepted into Lightbend Scala). However, the SIP is implementation is very small and should have minor effect on compiler performance.
71
60
72
61
### Motivating examples
73
62
74
-
The [singleton-ops library](https://github.com/fthomas/singleton-ops) with [Typelevel Scala](https://github.com/typelevel/scala) (which implemented [SIP-23](http://docs.scala-lang.org/sips/pending/42.type.html)) enable developers to express literal type operations more intuitively. For example:
63
+
The [singleton-ops library](https://github.com/fthomas/singleton-ops) with [Typelevel Scala](https://github.com/typelevel/scala) (which implemented [SIP-23](http://docs.scala-lang.org/sips/pending/42.type.html)) enable developers to express literal type operations more intuitively.
64
+
65
+
Consider the following example, where `foo` has two equivalent implementations, one using types, while the other uses terms:
75
66
76
67
```scala
77
68
importsingleton.ops._
@@ -81,8 +72,10 @@ object PrefixExample {
81
72
We would much rather write the following to acheive more clarity and shorter code:
82
73
type Foo[Cond1, Cond2, Num] = ITE[Cond1 && !Cond2, -Num, Num]
*[Typelevel Scala Issue #157](https://github.com/typelevel/scala/issues/157) (Resolved in recent update to SIP23)
147
153
148
-
Both SIP23 implementation and Dotty's implementation of literal types currently fail compilation when infix types interact with a negative literal type.
154
+
Dotty's implementation of literal types currently fail compilation when infix types interact with a negative literal type.
149
155
```scala
150
156
type~~[A, B]
151
157
typegood=2~~2
152
158
typebad=2~~-2//Error:(9, 20) ';' expected but integer literal found.
153
-
typework_around=2~~ (-2) //works for Typelevel scala, but fails in Dotty
159
+
typework_around=2~~ (-2) //Error in Dotty
154
160
```
155
-
It is not yet clear if this is an implementation issue, or if the spec should be changed to allow this as well.
156
-
If this is a spec change, then the committee should approve it also.
0 commit comments