From 5a1ff4130b217fba9bc3cd0def89da4970bf9143 Mon Sep 17 00:00:00 2001 From: Alexey Rykhalskiy Date: Thu, 19 Oct 2023 21:07:32 +0300 Subject: [PATCH] -- type lambda --- README.md | 1 - .../scala/fwd/ForwardReferenceProblem.scala | 29 +++++++++++++++++++ ce3/src/main/scala/gas104/Htttp.scala | 2 +- .../src/main/scala/advanced/TypeLambda1.scala | 1 + .../src/main/scala/advanced/TypeLambda3.scala | 28 ++++++++++++++++++ project/CompilerOptions.scala | 1 + repositories.md | 12 ++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 ce3/src/main/scala/fwd/ForwardReferenceProblem.scala create mode 100644 plain2/src/main/scala/advanced/TypeLambda3.scala create mode 100644 repositories.md diff --git a/README.md b/README.md index 1fde9174..edc0f0fa 100644 --- a/README.md +++ b/README.md @@ -130,4 +130,3 @@ I thought I knew Scala... - circe - shapeless - kafka streams processing -- \ No newline at end of file diff --git a/ce3/src/main/scala/fwd/ForwardReferenceProblem.scala b/ce3/src/main/scala/fwd/ForwardReferenceProblem.scala new file mode 100644 index 00000000..9ba3c6bb --- /dev/null +++ b/ce3/src/main/scala/fwd/ForwardReferenceProblem.scala @@ -0,0 +1,29 @@ +package fwd + +object ForwardReferenceProblem extends App { + + val x = y + val y = 5 + + println(s"x=$x") + println(s"y=$y") + + /** compilation fails 1: + * + * def noProblem1() = { + * val a = b + * val b = 1 + * } + * + */ + + /** compilation fails 1: + * + * def noProblem2() = for { + * b <- Option(a) + * a <- Option(1) + * } yield (a, b) + * + */ + +} diff --git a/ce3/src/main/scala/gas104/Htttp.scala b/ce3/src/main/scala/gas104/Htttp.scala index 05e57920..418a4f84 100644 --- a/ce3/src/main/scala/gas104/Htttp.scala +++ b/ce3/src/main/scala/gas104/Htttp.scala @@ -128,7 +128,7 @@ object Htttp { case Some(data) => data.traverse_ { x: Row => val r = URow.from(x) - val line = (r.dateTime, r.counter, r.delta) + val line = (r.dateTime.toLocalDate, r.counter, r.delta) Sync[F].delay(pprint.pprintln(line)) } case None => diff --git a/plain2/src/main/scala/advanced/TypeLambda1.scala b/plain2/src/main/scala/advanced/TypeLambda1.scala index 2571cfc6..74f95c80 100644 --- a/plain2/src/main/scala/advanced/TypeLambda1.scala +++ b/plain2/src/main/scala/advanced/TypeLambda1.scala @@ -96,6 +96,7 @@ object TypeLambda1 extends App { object solution22 { def foo2[F[_, _], B](f: Functor[({ type ab[C] = F[B, C] })#ab]) = ??? + // ============================= } object solution23 { diff --git a/plain2/src/main/scala/advanced/TypeLambda3.scala b/plain2/src/main/scala/advanced/TypeLambda3.scala new file mode 100644 index 00000000..554cdc8a --- /dev/null +++ b/plain2/src/main/scala/advanced/TypeLambda3.scala @@ -0,0 +1,28 @@ +package advanced + +object TypeLambda3 extends App { + + // Functor has one `hole` + trait Functor[F[_]] + + // MonadError has two `holes` + trait MonadError[F[_], E] + + // Functor can be specified as a type bounds + class Repository1[F[_]: Functor] + + // but MonadError can not + + // we can introduce type alias + type MonadErrorThrowable[F[_]] = MonadError[F, Throwable] + + // and use it + class Repository2[F[_]: MonadErrorThrowable] + + // or use type lambda and not declare alias + class Repository3[F[_]: ({ type MET[f[_]] = MonadError[f, Throwable] })#MET] + + // or use type lambda and not declare alias + class Repository4[F[_]: MonadError[*[_], Throwable]] + +} diff --git a/project/CompilerOptions.scala b/project/CompilerOptions.scala index 4b71b7fb..04946718 100644 --- a/project/CompilerOptions.scala +++ b/project/CompilerOptions.scala @@ -23,6 +23,7 @@ object CompilerOptions { warningsAsFatals, // ??? doesn't work as expected matchShouldBeExhaustive, lintDeprecation, + "-Xcheckinit", // "-Xlint:unsound-match", // "-Ypartial-unification", // by default since 2.13 "-language:existentials", diff --git a/repositories.md b/repositories.md new file mode 100644 index 00000000..aad41ff2 --- /dev/null +++ b/repositories.md @@ -0,0 +1,12 @@ +### repositories + +- https://github.com/alexr007/learning-scalajs2.git +- https://github.com/alexr007/learning-scalajs3.git +- https://github.com/alexr007/learning-fullstack.git +- https://github.com/alexr007/learning-doodle.git +- https://github.com/alexr007/learning-chartreuse.git +- https://github.com/alexr007/learning-chartreuse.git +- https://github.com/alexr007/learning-tyrian.git +- https://github.com/alexr007/learning-haskell.git +- https://github.com/alexr007/learning-rust.git +- \ No newline at end of file