Last active
June 16, 2026 04:53
-
-
Save lagenorhynque/0eec1d12bfeb92f1d8faeb334287a4df to your computer and use it in GitHub Desktop.
π¬'s first Flix example code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Sys.Process | |
| // The main entry point. | |
| def main(): Unit \ {Process, Abort, IO} = | |
| println("Hello World!"); | |
| let n = 5; | |
| println("The square of ${n} is ${square(n)}."); | |
| runProcess() | |
| |> Result.getOrAbort | |
| |> x -> println("Process output:\n${x}") | |
| def square(x: Int32): Int32 = | |
| x * x | |
| def runProcess(): Result[IoError, String] \ {Process, IO} = | |
| region rc { | |
| forM ( | |
| ph <- Process.exec("ls", Nil); | |
| out <- Process.stdout(ph); | |
| buf = Array.repeat(rc, 1024, 0i8); | |
| _ <- Readable.read(buf, out) | |
| ) yield buf |> Array.toVector |> String.fromBytes | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment