@@ -16,7 +16,7 @@ When saying that they have no effect on the runtime we do not only mean side eff
1616like IO, field mutation, exceptions and so on. We also imply that if a function receives
1717a phantom its result will not be affected by this argument.
1818
19- As phantom do not live at runtime they cannot be subtypes of ` scala.Any ` , which defines
19+ As phantoms do not live at runtime they cannot be subtypes of ` scala.Any ` , which defines
2020methods such as ` hashCode ` , ` equals ` , ` getClass ` , ` asInstanceOf ` and ` isInstanceOf ` .
2121All these operations cannot exist on phantoms as there will not be an underlying object
2222instance at runtime. At first glance this could look like a limitation, but in fact not
@@ -49,13 +49,13 @@ In fact we allow multiple phantom universes to exist.
4949 +---------+ +-------------------+ +------------------------+
5050```
5151
52- Inside a universe it types support the full Dotty type system. But we cannot mix types from
53- different universes with ` & ` , ` | ` or in type bounds. Each type must be fully defined one universe.
52+ Inside a universe the full Dotty type system is supported . But we cannot mix types from
53+ different universes with ` & ` , ` | ` or in type bounds. Each type must be fully defined in a single universe.
5454
5555
5656Implement your own phantom type
5757-------------------------------
58- Phantom types are definded by an ` object ` extending ` scala.Phantom ` . This object will represent
58+ Phantom types are defined by an ` object ` extending ` scala.Phantom ` . This object will represent
5959a universe of phantom types that is completely separated from types in ` scala.Any ` or other
6060phantom universes. We can define our phantom universe ` MyPhantoms ` .
6161
@@ -78,7 +78,7 @@ of the phantom types in `MyPhantoms`, these bounds are `protected` and can not b
7878from outside ` MyPhantoms ` unless an alias is defined for them.
7979
8080New phantom types can be defined using ` type XYZ <: OtherPhantom ` (where ` >: MyPhantom.Nothing `
81- will be inferred), this would be the equivalent of ` class XYZ extends OtherClass ` on a types
81+ will be inferred), this would be the equivalent of ` class XYZ extends OtherClass ` on types
8282only (no runtime definitions). Or aliased with ` type MyAny = OtherPhantom ` . Within ` MyPhantoms `
8383it is possible to refer to ` MyPhantoms.Any ` and ` MyPhantoms.Nothing ` with ` this.Any ` and
8484` this.Nothing ` (or just ` Any ` and ` Nothing ` but not recommended). Using this we will define
@@ -94,7 +94,7 @@ object MyPhantoms extends Phantom {
9494```
9595
9696Values of phantom type can be created using the ` protected def assume ` . This value can be
97- used as a value of this phantom type as it's type is ` this.Nothing ` (or ` MyPhantoms.Nothing ` ).
97+ used as a value of this phantom type as its type is ` this.Nothing ` (or ` MyPhantoms.Nothing ` ).
9898Usually this value will be used to define a ` implicit def ` that returns the phantom with a more
9999precise type. In our example we will only create values of type ` Pinky ` and ` Clyde `
100100
@@ -136,8 +136,8 @@ What happens with Phantoms at runtime?
136136
137137Disclaimer: Most of phantom erasure is implemented, but not all of is has been merged in ` dotty/master ` yet.
138138
139- As phantom have no effect on the result of a method invocation we just remove them for the call an definition.
140- The evaluation of the phantom parameter is still be done unless it can be optimized away.
139+ As phantoms have no effect on the result of a method invocation we just remove them for the call and definition.
140+ The evaluation of the phantom parameter is still done unless it can be optimized away.
141141By removing them we also restrict overloading as ` def f() ` and ` def f(x: MyPhantom) ` will
142142have the same signature in the bytecode, just use different names to avoid this.
143143
0 commit comments