Skip to content

Commit

Permalink
clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenjw committed Sep 12, 2023
1 parent b63deff commit 4e65938
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Scala/docs/Parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ val lf = vf.sequence map (_ reduce (_+_))
val l = Await.result(lf, 2.seconds)
println(l)
```
Crucially, this runs much faster than the corresponding sequential code.
Crucially, this runs much faster than the corresponding sequential code. However, it's still not as good as using parallel collections, since `map` and `reduce` are still the standard sequential versions, which are still $\mathcal{O}(n)$ operations. We could write our own `parMap` and `parReduce` methods, which use binary splitting to evaluate in parallel, but this is a bit beyond the scope of this very short course.

## Effects

Futures are a powerful and flexible way to construct parallel and concurrent applications. However, they aren't a perfect fit to a pure functional approach to programming. The fact that futures "fire" as soon as they are created means that they have a *side-effect* (such as creating a thread), and that is potentially problematic. People have developed more principled functional effects systems for Scala, such as [Cats effect](https://typelevel.org/cats-effect/) with its IO monad. These provide better mechanisms for parallel and concurrent programming in Scala. They are, however, (well) beyond the scope of this course.
Futures are a powerful and flexible way to construct parallel and concurrent applications. However, they aren't a perfect fit to a pure functional approach to programming. The fact that futures "fire" as soon as they are created means that they have a *side-effect* (such as creating a thread), and that is potentially problematic. People have developed more principled functional effects systems for Scala, such as [Cats effect](https://typelevel.org/cats-effect/) with its `IO` monad. These provide better mechanisms for parallel and concurrent programming in Scala. They are, however, (well) beyond the scope of this course.

6 changes: 3 additions & 3 deletions Scala/md/Parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This simplest (but by no means the only) way to get started with parallel progra
Let's create some random data:
```scala
val rng = scala.util.Random(42)
// rng: Random = scala.util.Random@18877d
// rng: Random = scala.util.Random@4fbdbb7
val v = Vector.fill(10)(rng.nextGaussian)
// v: Vector[Double] = Vector(
// 1.1419053154730547,
Expand Down Expand Up @@ -98,9 +98,9 @@ val l = Await.result(lf, 2.seconds)
println(l)
// -4.844171665682075
```
Crucially, this runs much faster than the corresponding sequential code.
Crucially, this runs much faster than the corresponding sequential code. However, it's still not as good as using parallel collections, since `map` and `reduce` are still the standard sequential versions, which are still $\mathcal{O}(n)$ operations. We could write our own `parMap` and `parReduce` methods, which use binary splitting to evaluate in parallel, but this is a bit beyond the scope of this very short course.

## Effects

Futures are a powerful and flexible way to construct parallel and concurrent applications. However, they aren't a perfect fit to a pure functional approach to programming. The fact that futures "fire" as soon as they are created means that they have a *side-effect* (such as creating a thread), and that is potentially problematic. People have developed more principled functional effects systems for Scala, such as [Cats effect](https://typelevel.org/cats-effect/) with its IO monad. These provide better mechanisms for parallel and concurrent programming in Scala. They are, however, (well) beyond the scope of this course.
Futures are a powerful and flexible way to construct parallel and concurrent applications. However, they aren't a perfect fit to a pure functional approach to programming. The fact that futures "fire" as soon as they are created means that they have a *side-effect* (such as creating a thread), and that is potentially problematic. People have developed more principled functional effects systems for Scala, such as [Cats effect](https://typelevel.org/cats-effect/) with its `IO` monad. These provide better mechanisms for parallel and concurrent programming in Scala. They are, however, (well) beyond the scope of this course.

2 changes: 1 addition & 1 deletion Scala/md/ScalaCC.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def linFun(m: Double, c: Double)(x: Double): Double =
m*x + c

val f = linFun(2, 3)
// f: Function1[Double, Double] = repl.MdocSession$MdocApp$$Lambda$8163/0x00000008020d8208@445113d1
// f: Function1[Double, Double] = repl.MdocSession$MdocApp$$Lambda$8192/0x0000000802165e08@36ff03be

f(0)
// res22: Double = 3.0
Expand Down

0 comments on commit 4e65938

Please sign in to comment.