11---
22layout : sip
3- title : SIP-ZZ - Opaque types
3+ title : SIP-35 - Opaque types
44
55vote-status : pending
66permalink : /sips/:title.html
@@ -33,14 +33,14 @@ Some use cases for opaque types are:
3333
3434 * Classes representing units of measure. Again, no boxing overhead
3535 would be incurred for these classes.
36-
36+
3737 * Classes representing different entities with the same underlying type,
3838 such as ` Id ` and ` Password ` being defined in terms of ` String ` .
39-
39+
4040We expand on all these points in our [ Motivation] ( motivation ) section.
4141
4242For a definition of boxing and previous state-of-the-art, we recommend reading [ SIP-15] .
43-
43+
4444### Implementation note
4545
4646The proposal is currently in an early stage.
@@ -83,7 +83,7 @@ package object valueclass {
8383 def + (that : Logarithm ): Logarithm = Logarithm (toDouble + that.toDouble)
8484 def * (that : Logarithm ): Logarithm = new Logarithm (exponent + that.exponent)
8585 }
86-
86+
8787 object Logarithm {
8888 def apply (x : Double ): Logarithm = new Logarithm (math.log(x))
8989 }
@@ -92,7 +92,7 @@ package object valueclass {
9292package object usesites {
9393 // 1e7 is approximately (e ** 16.11809565095832),
9494 // so x is encoded as 16.11809565095832.
95- val x : Logarithm = Logarithm (1e7 )
95+ val x : Logarithm = Logarithm (1e7 )
9696}
9797```
9898
@@ -183,7 +183,7 @@ package object opaquetypes {
183183
184184 def safe (d : Double ): Option [Logarithm ] =
185185 if (d > 0.0 ) Some (math.log(d)) else None
186-
186+
187187 // This is the first way to unlift the logarithm type
188188 def exponent (l : Logarithm ): Double = l
189189
@@ -204,7 +204,7 @@ The above `Logarithm` type companion contains the following definitions:
204204 * Methods to lower the type from ` Logarithm ` to ` Double ` (i.e. ` exponent ` )
205205 * Extension methods to unlift the type from ` Logarithm ` to ` Double ` (i.e. ` toDouble ` )
206206 * Extension methods to define more operations on the type (i.e. like ` + ` and ` * ` )
207-
207+
208208The key peculiarity of opaque types is that they behave like normal
209209[ type alias] es inside their type companion; that is, users can convert from
210210the type alias and its equivalent definition interchangeably without the use of
@@ -337,7 +337,7 @@ companion class of the module does not have a notion of companion type.
337337
338338#### Opaque type companions and implicit search
339339
340- These opaque type companions are also part of the implicit search scope of the opaque type ` t ` .
340+ These opaque type companions are also part of the implicit search scope of the opaque type ` t ` .
341341Therefore, uses of extension methods defined in the opaque type companion do not require users
342342to import the opaque type companion explicitly.
343343
@@ -751,7 +751,7 @@ There are several key ideas in the current, work-in-progress implementation:
751751
752752 * Phases after typer always dealias opaque types. This way, erasure and codegen can unwrap opaque
753753 types out of the box and, at the bytecode level, their underlying representation is used instead.
754-
754+
755755All these ideas are open to refinements by the SIP Committee.
756756
757757### On removing ` asInstanceOf ` at compile-time
0 commit comments