diff --git a/src/page/Home.js b/src/page/Home.js index fb35276..c0740f6 100644 --- a/src/page/Home.js +++ b/src/page/Home.js @@ -238,6 +238,60 @@ def map(f: a -> b \\ ef, l: List[a]): List[b] \\ ef = + + + + +

Algebraic Effects

+ +

+ Flix supports algebraic effects, i.e. user-defined effects and handlers. + In particular, Flix supports multi-shot resumptions. +

+ +

+ Effect-oriented programming, with algebraic effects, allow programmers to + write pure functions modulo effects. Effect handlers enable program reasoning, + modularity, and testability. +

+ +

+ For example, the program expresses a greeting function that is pure + modulo the current time of the day. In main we call the function + and handle the HourOfDay effect by getting the real-world time + from Java's LocalDateTime. +

+
+
+
+ + + + {`import java.time.LocalDateTime + +eff HourOfDay { + def getCurrentHour(): Int32 +} + +def greeting(): String \\ {HourOfDay} = + let h = HourOfDay.getCurrentHour(); + if (h <= 12) "Good morning" + else if (h <= 18) "Good afternoon" + else "Good evening" + +def main(): Unit \\ IO = + run { + println(greeting()) + } with HourOfDay { + def getCurrentHour(_, resume) = + let dt = LocalDateTime.now(); + resume(dt.getHour()) + } +`} + + +
+ @@ -346,60 +400,6 @@ def map(f: a -> b \\ ef, l: LazyList[a]): LazyList[b] \\ ef = - - - - -

Algebraic Effects

- -

- Flix supports algebraic effects, i.e. user-defined effects and handlers. - In particular, Flix supports multi-shot resumptions. -

- -

- Effect-oriented programming, with algebraic effects, allow programmers to - write pure functions modulo effects. Effect handlers enable program reasoning, - modularity, and testability. -

- -

- For example, the program expresses a greeting function that is pure - modulo the current time of the day. In main we call the function - and handle the HourOfDay effect by getting the real-world time - from Java's LocalDateTime. -

-
-
-
- - - - {`import java.time.LocalDateTime - -eff HourOfDay { - def getCurrentHour(): Int32 -} - -def greeting(): String \\ {HourOfDay} = - let h = HourOfDay.getCurrentHour(); - if (h <= 12) "Good morning" - else if (h <= 18) "Good afternoon" - else "Good evening" - -def main(): Unit \\ IO = - run { - println(greeting()) - } with HourOfDay { - def getCurrentHour(_, resume) = - let dt = LocalDateTime.now(); - resume(dt.getHour()) - } -`} - - -
-