Skip to content

Commit

Permalink
-- type lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed Oct 19, 2023
1 parent 749d507 commit 5a1ff41
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,3 @@ I thought I knew Scala...
- circe
- shapeless
- kafka streams processing
-
29 changes: 29 additions & 0 deletions ce3/src/main/scala/fwd/ForwardReferenceProblem.scala
Original file line number Diff line number Diff line change
@@ -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)
*
*/

}
2 changes: 1 addition & 1 deletion ce3/src/main/scala/gas104/Htttp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
1 change: 1 addition & 0 deletions plain2/src/main/scala/advanced/TypeLambda1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions plain2/src/main/scala/advanced/TypeLambda3.scala
Original file line number Diff line number Diff line change
@@ -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]]

}
1 change: 1 addition & 0 deletions project/CompilerOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions repositories.md
Original file line number Diff line number Diff line change
@@ -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
-

0 comments on commit 5a1ff41

Please sign in to comment.