Skip to content

Update phantom-types.md (typos/grammar) #2992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/docs/reference/phantom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ package scala
trait Phantom { // only an `object` can extend this trait
protected final type Any // not a subtype of scala.Any
protected final type Nothing // subtype of every subtype of this.Any
protected final def assume: this.Nothig
protected final def assume: this.Nothing
}
```

Expand All @@ -81,8 +81,8 @@ New phantom types can be defined using `type XYZ <: OtherPhantom` (where `>: MyP
will be inferred), this would be the equivalent of `class XYZ extends OtherClass` on a types
only (no runtime definitions). Or aliased with `type MyAny = OtherPhantom`. Within `MyPhantoms`
it is possible to refer to `MyPhantoms.Any` and `MyPhantoms.Nothing` with `this.Any` and
`this.Nothing` (or just `Any` and `Nothing` but not recommended). Using this we will define
four the four phantoms: `Inky`, `Blinky`, `Pinky` and `Clyde`.
`this.Nothing` (or just `Any` and `Nothing` but not recommended). Using this we will define
the four phantoms: `Inky`, `Blinky`, `Pinky` and `Clyde`.

```scala
object MyPhantoms extends Phantom {
Expand All @@ -94,7 +94,7 @@ object MyPhantoms extends Phantom {
```

Values of phantom type can be created using the `protected def assume`. This value can be
used as a value of this phantom type as it's type is `this.Nothig` (or `MyPhantoms.Nothing`).
used as a value of this phantom type as it's type is `this.Nothing` (or `MyPhantoms.Nothing`).
Usually this value will be used to define a `implicit def` that returns the phantom with a more
precise type. In our example we will only create values of type `Pinky` and `Clyde`

Expand All @@ -109,7 +109,7 @@ object MyPhantoms extends Phantom {

### Using the phantoms

From the user of the phantom type there is almost no difference, except for stronger type guarantees.
For the user of the phantom type there is almost no difference, except for stronger type guarantees.
We can look at the following simple application:

```scala
Expand All @@ -123,7 +123,7 @@ object MyApp {
}
```

Note given the way we defined the phantoms it is impossible to call the `hide` as we did not
Note that given the way we defined the phantoms it is impossible to call `hide` as we did not
expose any value of type `Blinky` to the user. We cannot call `hide(MyPhantoms.assume)` as
`assume` is protected, `hide(null.asInstanceOf[Blinky])` does not compile because it is impossible
to cast to a phantom and `hide(throw new Exception)` (or `hide(???)`) does not compile as `throw` of
Expand Down