diff --git a/crates/compiler/builtins/roc/Result.roc b/crates/compiler/builtins/roc/Result.roc index 0cef01cc02..e1a9ad1926 100644 --- a/crates/compiler/builtins/roc/Result.roc +++ b/crates/compiler/builtins/roc/Result.roc @@ -1,5 +1,5 @@ interface Result - exposes [Result, isOk, isErr, map, mapErr, try, onErr, withDefault, unwrapOk, unwrapErr] + exposes [Result, isOk, isErr, map, mapErr, try, onErr, withDefault] imports [Bool.{ Bool }] ## The result of an operation that could fail: either the operation went diff --git a/examples/interactive/cli-platform/Effect.roc b/examples/interactive/cli-platform/Effect.roc index 7b2b8274dd..b423e9f067 100644 --- a/examples/interactive/cli-platform/Effect.roc +++ b/examples/interactive/cli-platform/Effect.roc @@ -8,6 +8,7 @@ hosted Effect forever, loop, dirList, + envDict, cwd, stdoutLine, stderrLine, diff --git a/examples/interactive/cli-platform/Env.roc b/examples/interactive/cli-platform/Env.roc index cd3274b18e..56038ef4de 100644 --- a/examples/interactive/cli-platform/Env.roc +++ b/examples/interactive/cli-platform/Env.roc @@ -1,5 +1,5 @@ interface Env - exposes [cwd] + exposes [cwd, dict] imports [Task.{ Task }, Path.{ Path }, InternalPath, Effect, InternalTask] ## Reads the [current working directory](https://en.wikipedia.org/wiki/Working_directory) diff --git a/examples/interactive/cli-platform/InternalProgram.roc b/examples/interactive/cli-platform/InternalProgram.roc index 5974ced7be..05b6c65bc3 100644 --- a/examples/interactive/cli-platform/InternalProgram.roc +++ b/examples/interactive/cli-platform/InternalProgram.roc @@ -1,6 +1,6 @@ interface InternalProgram exposes [InternalProgram, fromEffect, toEffect] - imports [] + imports [Effect.{ Effect }] InternalProgram := Effect U8 @@ -8,4 +8,4 @@ fromEffect : Effect U8 -> InternalProgram fromEffect = @InternalProgram toEffect : InternalProgram -> Effect U8 -toEffect = \InternalProgram @effect -> effect \ No newline at end of file +toEffect = \@InternalProgram effect -> effect \ No newline at end of file diff --git a/examples/interactive/cli-platform/Program.roc b/examples/interactive/cli-platform/Program.roc index 149292f4b2..82a16d008b 100644 --- a/examples/interactive/cli-platform/Program.roc +++ b/examples/interactive/cli-platform/Program.roc @@ -1,6 +1,6 @@ interface Program - exposes [Program, noArgs, withArgs, withNonUnicodeArgs] - imports [Task.{ Task }, InternalProgram.{ InternalProgram }] + exposes [Program, noArgs, withArgs, quick, withEnv] + imports [Task.{ Task }, InternalProgram.{ InternalProgram }, InternalTask, Effect] ## A [command-line interface](https://en.wikipedia.org/wiki/Command-line_interface) program. Program : InternalProgram diff --git a/examples/interactive/cli-platform/main.roc b/examples/interactive/cli-platform/main.roc index e01d9a16e1..9877ce9ac5 100644 --- a/examples/interactive/cli-platform/main.roc +++ b/examples/interactive/cli-platform/main.roc @@ -5,5 +5,5 @@ platform "cli" imports [Effect.{ Effect }, InternalProgram.{ InternalProgram }] provides [mainForHost] -mainForHost : List Str -> Effect U8 as Fx -mainForHost = \args -> InternalProgram.toEffect main args +mainForHost : Effect U8 as Fx +mainForHost = InternalProgram.toEffect main diff --git a/examples/interactive/file.roc b/examples/interactive/file.roc index c022f2e1f9..0bba8e16fc 100644 --- a/examples/interactive/file.roc +++ b/examples/interactive/file.roc @@ -1,10 +1,22 @@ app "file-io" packages { pf: "cli-platform/main.roc" } - imports [pf.Stdout, pf.Stderr, pf.Task, pf.File, pf.Path, pf.Env, pf.Dir] + imports [ + pf.Program.{ Program }, + pf.Stdout, + pf.Stderr, + pf.Task.{ Task }, + pf.File, + pf.Path, + pf.Env, + pf.Dir, + ] provides [main] to pf -main : Task.Task {} [] [Write [File, Stdout, Stderr], Read [File], Env] -main = +main : Program +main = Program.noArgs mainTask + +mainTask : Task U8 [] [Write [File, Stdout, Stderr], Read [File], Env] +mainTask = path = Path.fromStr "out.txt" task = cwd <- Env.cwd |> Task.await @@ -21,10 +33,14 @@ main = Stdout.line "I read the file back. Its contents: \"\(contents)\"" Task.attempt task \result -> - when result is - Err (FileWriteErr _ PermissionDenied) -> Stderr.line "Err: PermissionDenied" - Err (FileWriteErr _ Unsupported) -> Stderr.line "Err: Unsupported" - Err (FileWriteErr _ (Unrecognized _ other)) -> Stderr.line "Err: \(other)" - Err (FileReadErr _ _) -> Stderr.line "Error reading file" - Err _ -> Stderr.line "Uh oh, there was an error!" - Ok _ -> Stdout.line "Successfully wrote a string to out.txt" + msg = when result is + Err (FileWriteErr _ PermissionDenied) -> Err "PermissionDenied" + Err (FileWriteErr _ Unsupported) -> Err "Unsupported" + Err (FileWriteErr _ (Unrecognized _ other)) -> Err other + Err (FileReadErr _ _) -> Err "Error reading file" + Err _ -> Err "Uh oh, there was an error!" + Ok _ -> Ok "Successfully wrote a string to out.txt" + + when msg is + Ok ok -> Task.await (Stdout.line ok) \{} -> Task.succeed 0 + Err err -> Task.await (Stderr.line err) \{} -> Task.succeed 1