From 991ea6206b98889aefa57f4c62c8985517f9debf Mon Sep 17 00:00:00 2001 From: xhudik Date: Tue, 9 Mar 2021 22:43:56 +0100 Subject: [PATCH 1/2] reduced number of Logarithm --- docs/docs/reference/other-new-features/opaques.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/reference/other-new-features/opaques.md b/docs/docs/reference/other-new-features/opaques.md index 61a2bd541f56..cf29af4dcd48 100644 --- a/docs/docs/reference/other-new-features/opaques.md +++ b/docs/docs/reference/other-new-features/opaques.md @@ -6,7 +6,7 @@ title: "Opaque Type Aliases" Opaque types aliases provide type abstraction without any overhead. Example: ```scala -object Logarithms: +object MyMath: opaque type Logarithm = Double @@ -27,7 +27,7 @@ object Logarithms: def + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y)) def * (y: Logarithm): Logarithm = x + y -end Logarithms +end MyMath ``` This introduces `Logarithm` as a new abstract type, which is implemented as `Double`. @@ -41,7 +41,7 @@ They convert from `Double`s to `Logarithm` values. Moreover, an operation `toDou The following operations would be valid because they use functionality implemented in the `Logarithms` object. ```scala -import Logarithms.Logarithm +import MyMath.Logarithm val l = Logarithm(1.0) val l2 = Logarithm(2.0) From 4b77a191ce0442110790a236397410860ad8d8af Mon Sep 17 00:00:00 2001 From: xhudik Date: Fri, 12 Mar 2021 12:32:05 +0100 Subject: [PATCH 2/2] fixed: Logarithms->MyMaths in text --- docs/docs/reference/other-new-features/opaques.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/reference/other-new-features/opaques.md b/docs/docs/reference/other-new-features/opaques.md index cf29af4dcd48..3d1d5acd04a1 100644 --- a/docs/docs/reference/other-new-features/opaques.md +++ b/docs/docs/reference/other-new-features/opaques.md @@ -32,13 +32,13 @@ end MyMath This introduces `Logarithm` as a new abstract type, which is implemented as `Double`. The fact that `Logarithm` is the same as `Double` is only known in the scope where -`Logarithm` is defined which in the above example corresponds to the object `Logarithms`. +`Logarithm` is defined which in the above example corresponds to the object `MyMath`. Or in other words, within the scope it is treated as type alias, but this is opaque to the outside world where in consequence `Logarithm` is seen as an abstract type and has nothing to do with `Double`. The public API of `Logarithm` consists of the `apply` and `safe` methods defined in the companion object. 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. -The following operations would be valid because they use functionality implemented in the `Logarithms` object. +The following operations would be valid because they use functionality implemented in the `MyMath` object. ```scala import MyMath.Logarithm