Skip to content

Commit 0c01817

Browse files
committed
Apply implied changes
1 parent 7d306d5 commit 0c01817

File tree

7 files changed

+22
-24
lines changed

7 files changed

+22
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ You will need to make the following adjustments to your build:
2727

2828
### project/plugins.sbt
2929
```scala
30-
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.6")
30+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.0")
3131
```
3232

3333
### project/build.properties
3434
```scala
35-
sbt.version=1.2.3
35+
sbt.version=1.2.7
3636
```
3737

3838
Older versions of sbt are not supported.

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.3
1+
sbt.version=1.2.7

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.6")
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.0")

src/main/scala/ImplicitFunctions.scala renamed to src/main/scala/ContextQueries.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@ import scala.concurrent.{ExecutionContext, Future}
33
import scala.util.Try
44

55
/**
6-
* Implicit Function Types:
7-
* - http://dotty.epfl.ch/docs/reference/implicit-function-types.html,
6+
* Context Queries:
7+
* - http://dotty.epfl.ch/docs/reference/contextual/query-types.html,
88
* - https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html
99
*/
10-
object ImplicitFunctions {
10+
object ContextQueries /* Formerly known as Implicit Function Types */ {
1111

1212
object context {
1313
// type alias Contextual
14-
type Contextual[T] = implicit ExecutionContext => T
14+
type Contextual[T] = given ExecutionContext => T
1515

1616
// sum is expanded to sum(x, y)(ctx)
1717
def asyncSum(x: Int, y: Int): Contextual[Future[Int]] = Future(x + y)
1818

19-
def asyncMult(x: Int, y: Int) = { implicit ctx: ExecutionContext =>
20-
Future(x * y)
21-
}
19+
def asyncMult(x: Int, y: Int) given (ctx: ExecutionContext) = Future(x * y)
2220
}
2321

2422
object parse {
2523

26-
type Parseable[T] = implicit ImplicitParams.StringParser[T] => Try[T]
24+
type Parseable[T] = given ImplicitParams.StringParser[T] => Try[T]
2725

2826
def sumStrings(x: String, y: String): Parseable[Int] = {
2927
val parser = implicitly[ImplicitParams.StringParser[Int]]

src/main/scala/ImplicitConversion.scala renamed to src/main/scala/Conversion.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import scala.language.implicitConversions
22

33
/**
4-
* Implicit Conversions: http://dotty.epfl.ch/docs/reference/changed-features/implicit-conversions.html
4+
* Conversions: http://dotty.epfl.ch/docs/reference/contextual/conversions.html
55
*/
6-
object ImplicitConversion {
6+
object Conversion {
77

88
case class IntWrapper(a: Int) extends AnyVal
99
case class DoubleWrapper(b: Double) extends AnyVal
1010

11-
def convert[T, U](x: T)(implicit converter: ImplicitConverter[T, U]): U = converter(x)
11+
def convert[T, U](x: T) given (converter: Conversion[T, U]): U = converter(x)
1212

13-
implicit val IntWrapperToDoubleWrapper: ImplicitConverter[IntWrapper, DoubleWrapper] = new ImplicitConverter[IntWrapper, DoubleWrapper] {
13+
implied IntWrapperToDoubleWrapper for Conversion[IntWrapper, DoubleWrapper] = new Conversion[IntWrapper, DoubleWrapper] {
1414
override def apply(i: IntWrapper): DoubleWrapper = new DoubleWrapper(i.a.toDouble)
1515
}
1616

17-
def useConversion(implicit f: ImplicitConverter[IntWrapper, DoubleWrapper]) = {
17+
def useConversion given (f: Conversion[IntWrapper, DoubleWrapper]) = {
1818
val y: IntWrapper = new IntWrapper(4)
1919
val x: DoubleWrapper = y
2020
x

src/main/scala/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ object Main {
77

88
runExample("Enum Types")(EnumTypes.test)
99

10-
runExample("Implicit Functions")(ImplicitFunctions.test)
10+
runExample("Context Queries")(ContextQueries.test)
1111

1212
runExample("Implicit Params")(ImplicitParams.test)
1313

14-
runExample("Implicit Conversion")(ImplicitConversion.test)
14+
runExample("Conversion")(Conversion.test)
1515

1616
runExample("Union Types")(UnionTypes.test)
1717

src/main/scala/MultiversalEquality.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import scala.language.strictEquality
22

33
/**
4-
* Multiversal Equality: http://dotty.epfl.ch/docs/reference/multiversal-equality.html
5-
* scala.Eq definition: https://github.com/lampepfl/dotty/blob/master/library/src/scala/Eq.scala
4+
* Multiversal Equality: https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality.html
5+
* scala.Eq definition: https://github.com/lampepfl/dotty/blob/master/library/src/scala/Eql.scala
66
*/
77
object MultiversalEquality {
88

99
def test: Unit = {
1010

1111
// Values of types Int and String cannot be compared with == or !=,
1212
// unless we add a custom implicit like:
13-
implicit def eqIntString: Eq[Int, String] = Eq
13+
implicit def eqIntString: Eql[Int, String] = Eql.derived
1414
println(3 == "3")
1515

1616
// By default, all numbers are comparable, because of;
@@ -29,8 +29,8 @@ object MultiversalEquality {
2929

3030
// scala.language.strictEquality is enabled, therefore we need some extra implicits
3131
// to compare instances of A and B.
32-
implicit def eqAB: Eq[A, B] = Eq
33-
implicit def eqBA: Eq[B, A] = Eq
32+
implicit def eqAB: Eql[A, B] = Eql.derived
33+
implicit def eqBA: Eql[B, A] = Eql.derived
3434

3535
println(a != b)
3636
println(b == a)

0 commit comments

Comments
 (0)