From b6a1a276edf8612b5a66accd56ddc0ca249d8c69 Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Mon, 1 Jan 2024 13:25:31 +0100 Subject: [PATCH] feat: update `Home.js` --- build-scripts/sampleFiles.mjs | 12 ----- src/page/Home.js | 86 ++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/build-scripts/sampleFiles.mjs b/build-scripts/sampleFiles.mjs index d851765..44d0170 100644 --- a/build-scripts/sampleFiles.mjs +++ b/build-scripts/sampleFiles.mjs @@ -100,17 +100,5 @@ export const sampleFiles = [ { name: "Working with Files and Directories", file: "working-with-files-and-directories.flix", - }, - { - name: "Using Laziness for Infinite Streams", - file: "using-laziness-for-infinite-streams.flix", - }, - { - name: "Using Laziness for Logging", - file: "using-laziness-for-logging.flix", - }, - { - name: "Using Laziness to Compute Fibonacci", - file: "using-laziness-to-compute-fibonacci.flix", } ]; \ No newline at end of file diff --git a/src/page/Home.js b/src/page/Home.js index 95300fc..144fd64 100644 --- a/src/page/Home.js +++ b/src/page/Home.js @@ -77,7 +77,8 @@ class Home extends Component {

- Flix also supports several unique features, + Flix also supports several unique features, including: a polymorphic effect system, region-based local mutation, b \\ ef, l: LazyList[a]): LazyList[b] \\ ef = -

Traits (Type Classes)

+

Parallelism

+ +

+ Flix makes it simple and easy to evaluate pure code in parallel. +

+

+ For example, the code on the right shows a parallel implementation of + the List.map function using the par construct. +

+

+ Internally, the par construct uses + light-weight VirtualThreads. +

+
+ + + + + + {`/// +/// A parallel implementation of the List.map function. +/// +def parMap(f: a -> b, l: List[a]): List[b] = match l { + case Nil => Nil + case x :: xs => + // Evaluate f(x) and parMap(f, xs) in parallel. + par (r <- f(x); rs <- parMap(f, xs)) + yield r :: rs +}`} + + + + + + + + {`def main(): Unit \\ IO = + region rc { + // A channel which can buffer one message. + let (tx, rx) = Channel.buffered(rc, 1); + spawn say("Meow!", tx) @ rc; // thread 1 + spawn say("Woof!", tx) @ rc; // thread 2 + Channel.recv(rx) |> println + } // Execution is blocked until both threads finish. + +/// Sends the string s on the given channel tx. +def say(s: String, tx: Sender[String, r]): Unit \\ r = + Channel.send(s, tx) + +`} + + + + + +

Structured Concurrency

+ +

+ Flix supports structured + concurrency. +

+

+ For example, the code on the left shows the creation of a fresh + region named rc in which two threads are spawned. +

+

+ Importantly, control-flow does not leave the region before both threads + have terminated. Hence the two threads cannot outlive the lifetime of their + enclosing region. +

+
+
+
+ +
+ + + + + +

Traits

Flix uses traits to abstract over types that support a common set of