From 4b6718be3bdad84a7ccde74ac139ebdd7cde3f46 Mon Sep 17 00:00:00 2001 From: MarkPoloz <147072230+MarkPoloz@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:48:12 +0500 Subject: [PATCH 1/4] Update console-output.txt --- .../homework_1/task_1/console-output.txt | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/homeworks/homework_1/task_1/console-output.txt b/homeworks/homework_1/task_1/console-output.txt index e69de29b..75557812 100644 --- a/homeworks/homework_1/task_1/console-output.txt +++ b/homeworks/homework_1/task_1/console-output.txt @@ -0,0 +1,72 @@ +PS C:\Users\Y\IdeaProjects\naumen_scala_urfu_2023\naumen.scala.course.2023.spring> scala +Welcome to Scala 2.12.10 (Java HotSpot(TM) 64-Bit Server VM, Java 19.0.1). +Type in expressions for evaluation. Or try :help. + +scala> println("Ni hao") +Ni hao + +scala> println("Hello Scala! This is Yaroslav") +Hello Scala! This is Yaroslav + +scala> val name = Yaroslav Churikov +:11: error: not found: value Yaroslav + val name = Yaroslav Churikov + ^ +:11: warning: postfix operator Churikov should be enabled +by making the implicit value scala.language.postfixOps visible. +This can be achieved by adding the import clause 'import scala.language.postfixOps' +or by setting the compiler option -language:postfixOps. +See the Scaladoc for value scala.language.postfixOps for a discussion +why the feature should be explicitly enabled. + val name = Yaroslav Churikov + ^ + +scala> val name = "Yaroslav Churikov" +name: String = Yaroslav Churikov + +scala> val small_turple = ("Hello","Hola","Guten tag") +small_turple: (String, String, String) = (Hello,Hola,Guten tag) + +scala> val phrase = " Scala! This is " +phrase: String = " Scala! This is " + +scala> println(small_turple(1) + phrase + name) +:15: error: (String, String, String) does not take parameters + println(small_turple(1) + phrase + name) + ^ + +scala> println(small_turple) +(Hello,Hola,Guten tag) + +scala> small_turple.getClass +res4: Class[_ <: (String, String, String)] = class scala.Tuple3 + +scala> small_turple(0) +:13: error: (String, String, String) does not take parameters + small_turple(0) + ^ + +scala> small_turple.0 +:1: error: ';' expected but double literal found. + small_turple.0 + ^ + +scala> small_turple[0] +:1: error: identifier expected but integer literal found. + small_turple[0] + ^ + +scala> small_turple._1 +res6: String = Hello + + +scala> val new_seq = Seq("Hello","Hola","Guten tag") +new_seq: Seq[String] = List(Hello, Hola, Guten tag) + +scala> for (elem <- new_seq) println(elem + phrase + name) +Hello Scala! This is Yaroslav Churikov +Hola Scala! This is Yaroslav Churikov +Guten tag Scala! This is Yaroslav Churikov + + +scala> From 40ec4fb129db7715aed5f42c0504abc6b1094485 Mon Sep 17 00:00:00 2001 From: MarkPoloz <147072230+MarkPoloz@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:58:31 +0500 Subject: [PATCH 2/4] Update console-output.txt --- .../homework_1/task_1/console-output.txt | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/homeworks/homework_1/task_1/console-output.txt b/homeworks/homework_1/task_1/console-output.txt index 75557812..173bee60 100644 --- a/homeworks/homework_1/task_1/console-output.txt +++ b/homeworks/homework_1/task_1/console-output.txt @@ -5,27 +5,27 @@ Type in expressions for evaluation. Or try :help. scala> println("Ni hao") Ni hao -scala> println("Hello Scala! This is Yaroslav") -Hello Scala! This is Yaroslav +scala> println("Hello Scala! This is Mark") +Hello Scala! This is Mark -scala> val name = Yaroslav Churikov -:11: error: not found: value Yaroslav - val name = Yaroslav Churikov +scala> val name = Mark Polozkov +:11: error: not found: value Mark + val name = Mark Polozkov ^ -:11: warning: postfix operator Churikov should be enabled +:11: warning: postfix operator Poloz should be enabled by making the implicit value scala.language.postfixOps visible. This can be achieved by adding the import clause 'import scala.language.postfixOps' or by setting the compiler option -language:postfixOps. See the Scaladoc for value scala.language.postfixOps for a discussion why the feature should be explicitly enabled. - val name = Yaroslav Churikov + val name = Mark Polozkov ^ -scala> val name = "Yaroslav Churikov" -name: String = Yaroslav Churikov +scala> val name = "Mark Polozkov" +name: String = Mark Polozkov -scala> val small_turple = ("Hello","Hola","Guten tag") -small_turple: (String, String, String) = (Hello,Hola,Guten tag) +scala> val small_turple = ("Hello","Hola","Guten morgen") +small_turple: (String, String, String) = (Hello,Hola,Guten morgen) scala> val phrase = " Scala! This is " phrase: String = " Scala! This is " @@ -36,7 +36,7 @@ scala> println(small_turple(1) + phrase + name) ^ scala> println(small_turple) -(Hello,Hola,Guten tag) +(Hello,Hola,Guten morgen) scala> small_turple.getClass res4: Class[_ <: (String, String, String)] = class scala.Tuple3 @@ -60,13 +60,13 @@ scala> small_turple._1 res6: String = Hello -scala> val new_seq = Seq("Hello","Hola","Guten tag") -new_seq: Seq[String] = List(Hello, Hola, Guten tag) +scala> val new_seq = Seq("Hello","Hola","Guten morgen") +new_seq: Seq[String] = List(Hello, Hola, Guten morgen) scala> for (elem <- new_seq) println(elem + phrase + name) -Hello Scala! This is Yaroslav Churikov -Hola Scala! This is Yaroslav Churikov -Guten tag Scala! This is Yaroslav Churikov +Hello Scala! This is Mark Polozkov +Hola Scala! This is Mark Polozkov +Guten morgen Scala! This is Mark Polozkov scala> From bf775b2c06c2e3d3e10f59f75265943fdc13dc80 Mon Sep 17 00:00:00 2001 From: MarkPoloz <147072230+MarkPoloz@users.noreply.github.com> Date: Wed, 8 Nov 2023 23:03:31 +0500 Subject: [PATCH 3/4] Update scastie-url.txt --- homeworks/homework_1/task_2/scastie-url.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/homeworks/homework_1/task_2/scastie-url.txt b/homeworks/homework_1/task_2/scastie-url.txt index e69de29b..cfaf820d 100644 --- a/homeworks/homework_1/task_2/scastie-url.txt +++ b/homeworks/homework_1/task_2/scastie-url.txt @@ -0,0 +1 @@ +https://scastie.scala-lang.org/aBFFrmeIT1e24FKS4rRy7Q From 35b1eb3fa2ca9ba3918335538a43887ba0ecef53 Mon Sep 17 00:00:00 2001 From: MarkPoloz <147072230+MarkPoloz@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:53:07 +0500 Subject: [PATCH 4/4] Update MonadFunctor.scala --- homeworks/homework_7/src/main/scala/MonadFunctor.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/homeworks/homework_7/src/main/scala/MonadFunctor.scala b/homeworks/homework_7/src/main/scala/MonadFunctor.scala index c90951a2..0992386e 100644 --- a/homeworks/homework_7/src/main/scala/MonadFunctor.scala +++ b/homeworks/homework_7/src/main/scala/MonadFunctor.scala @@ -1,23 +1,24 @@ - trait Monad[F[_]] { - def pure[A](a: A): F[A] def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] def map2[A, B, C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C] = ??? + def map2[A, B, C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C] = flatMap(fa)(x => flatMap(fb)(y => pure(f(x, y)))) def sequence[A](fas: List[F[A]]): F[List[A]] = ??? + def sequence[A](fas: List[F[A]]): F[List[A]] = fas.foldRight(pure(List[A]()))((a, b) => map2(a, b)((c, d) => c :: d)) def compose[A, B, C](f: A => F[B])(g: B => F[C]): A => F[C] = ??? + def compose[A, B, C](f: A => F[B])(g: B => F[C]): A => F[C] = a => flatMap(f(a))(g) } trait Functor[F[_]] { - def map[A, B](a: F[A])(f: A => B): F[B] -} +@@ -18,6 +18,6 @@ trait Functor[F[_]] { object Functor { def functorFromMonad[F[_]](M: Monad[F]): Functor[F] = new Functor[F] { def map[A, B](a: F[A])(f: A => B): F[B] = ??? + def map[A, B](a: F[A])(f: A => B): F[B] = M.flatMap(a)(b => M.pure(f(b))) } }