Skip to content

Commit 34064b2

Browse files
Merge pull request #11677 from xhudik/patch-1
reduced number of Logarithm
2 parents a3b98ac + 4b77a19 commit 34064b2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/docs/reference/other-new-features/opaques.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: "Opaque Type Aliases"
66
Opaque types aliases provide type abstraction without any overhead. Example:
77

88
```scala
9-
object Logarithms:
9+
object MyMath:
1010

1111
opaque type Logarithm = Double
1212

@@ -27,21 +27,21 @@ object Logarithms:
2727
def + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y))
2828
def * (y: Logarithm): Logarithm = x + y
2929

30-
end Logarithms
30+
end MyMath
3131
```
3232

3333
This introduces `Logarithm` as a new abstract type, which is implemented as `Double`.
3434
The fact that `Logarithm` is the same as `Double` is only known in the scope where
35-
`Logarithm` is defined which in the above example corresponds to the object `Logarithms`.
35+
`Logarithm` is defined which in the above example corresponds to the object `MyMath`.
3636
Or in other words, within the scope it is treated as type alias, but this is opaque to the outside world
3737
where in consequence `Logarithm` is seen as an abstract type and has nothing to do with `Double`.
3838

3939
The public API of `Logarithm` consists of the `apply` and `safe` methods defined in the companion object.
4040
They convert from `Double`s to `Logarithm` values. Moreover, an operation `toDouble` that converts the other way, and operations `+` and `*` are defined as extension methods on `Logarithm` values.
41-
The following operations would be valid because they use functionality implemented in the `Logarithms` object.
41+
The following operations would be valid because they use functionality implemented in the `MyMath` object.
4242

4343
```scala
44-
import Logarithms.Logarithm
44+
import MyMath.Logarithm
4545

4646
val l = Logarithm(1.0)
4747
val l2 = Logarithm(2.0)

0 commit comments

Comments
 (0)