Skip to content

Commit dfc5f8a

Browse files
committed
1 parent 780a350 commit dfc5f8a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

step03/src/main/scala/com/github/shinharad/gettingStartedWithScala3/OpaqueTypeAliases.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import scala.util.chaining.*
66
//---
77
// 実装例その1
88

9-
// - 以下は、Logarithms(対数)を抽象化したもので、実態は Double
10-
// - Double であるという事実は、Logarithms が定義しているスコープ内でのみ知られている
9+
// - 以下は、Logarithm(対数)を抽象化したもので、実態は Double
10+
// - Double であるという事実は、MyMath のスコープ内でのみ知られている
1111
// - スコープ内では Logarithm は型エイリアスとして扱われるが、
1212
// スコープ外からは opaque(不透明)なので、Logarithm は抽象型として見られ、
1313
// 実態が Double であることを認識することはできない
14-
object Logarithms:
14+
object MyMath:
1515

1616
// 必ず何らかのスコープ内で定義する
1717
opaque type Logarithm = Double
@@ -30,10 +30,10 @@ object Logarithms:
3030
def + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y))
3131
def * (y: Logarithm): Logarithm = x + y
3232

33-
end Logarithms
33+
end MyMath
3434

3535
@main def no1(): Unit =
36-
import Logarithms.Logarithm
36+
import MyMath.Logarithm
3737

3838
println("-" * 50)
3939

@@ -156,7 +156,7 @@ end Access
156156
//
157157
// Opaque Type Aliases は、class と一緒に使用することもできる
158158

159-
class LogarithmsClass:
159+
class MyMathClass:
160160

161161
opaque type Logarithm = Double
162162

@@ -172,8 +172,8 @@ class LogarithmsClass:
172172

173173
// 異なるインスタンスの Opaque Type のメンバーは異なるものとして扱われる
174174

175-
val l1 = new LogarithmsClass
176-
val l2 = new LogarithmsClass
175+
val l1 = new MyMathClass
176+
val l2 = new MyMathClass
177177
val x = l1(1.5)
178178
val y = l1(2.6)
179179
val z = l2(3.1)

0 commit comments

Comments
 (0)