From 1ccef46c393ecf317fbcd6ce255763d4b964c3a2 Mon Sep 17 00:00:00 2001 From: Ayush Date: Sun, 20 Dec 2020 13:57:12 +0100 Subject: [PATCH 1/3] Update type-classes.md Use the new syntax of `with` in given --- docs/docs/reference/contextual/type-classes.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/docs/reference/contextual/type-classes.md b/docs/docs/reference/contextual/type-classes.md index f12531ef2274..2e055e199182 100644 --- a/docs/docs/reference/contextual/type-classes.md +++ b/docs/docs/reference/contextual/type-classes.md @@ -26,7 +26,7 @@ trait Monoid[T] extends SemiGroup[T]: An implementation of this `Monoid` type class for the type `String` can be the following: ```scala -given Monoid[String]: +given Monoid[String] with extension (x: String) def combine (y: String): String = x.concat(y) def unit: String = "" ``` @@ -34,7 +34,7 @@ given Monoid[String]: Whereas for the type `Int` one could write the following: ```scala -given Monoid[Int]: +given Monoid[Int] with extension (x: Int) def combine (y: Int): Int = x + y def unit: Int = 0 ``` @@ -76,9 +76,9 @@ Which could read as follows: "A `Functor` for the type constructor `F[_]` repres This way, we could define an instance of `Functor` for the `List` type: ```scala -given Functor[List]: +given Functor[List] with def map[A, B](x: List[A], f: A => B): List[B] = - x.map(f) // List already has a `map` method + x.map(f) // List already has a `map` method ``` With this `given` instance in scope, everywhere a `Functor` is expected, the compiler will accept a `List` to be used. @@ -108,11 +108,10 @@ trait Functor[F[_]]: The instance of `Functor` for `List` now becomes: ```scala -given Functor[List]: +given Functor[List] with extension [A, B](xs: List[A]) def map(f: A => B): List[B] = xs.map(f) // List already has a `map` method - ``` It simplifies the `assertTransformation` method: From 14cecb5c63934983735f81d27295cc908b2b136d Mon Sep 17 00:00:00 2001 From: ayush Date: Mon, 21 Dec 2020 05:00:23 +0100 Subject: [PATCH 2/3] retrigger checks From dca2a577eff7f643b5f8084b9fcef54e03e36130 Mon Sep 17 00:00:00 2001 From: Ayush Date: Mon, 21 Dec 2020 10:26:30 +0100 Subject: [PATCH 3/3] Update derivation.md --- docs/docs/reference/contextual/derivation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index 1fec9cd62e58..5d54bb84828e 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -259,7 +259,8 @@ trait Eq[T] { } object Eq { - given Eq[Int] { + + given Eq[Int] with { def eqv(x: Int, y: Int) = x == y }