diff --git a/README.md b/README.md
index 878220d..6b31640 100644
--- a/README.md
+++ b/README.md
@@ -38,15 +38,15 @@ init! = \{} -> Ok {}
respond! : Request, Model => Result Response [ServerErr Str]_
respond! = \req, _ ->
# Log request datetime, method and url
- datetime = Utc.to_iso_8601 (Utc.now! {})
+ datetime = Utc.to_iso_8601(Utc.now!({}))
- try Stdout.line! "$(datetime) $(Inspect.toStr req.method) $(req.uri)"
+ Stdout.line!("$(datetime) $(Inspect.toStr req.method) $(req.uri)")?
- Ok {
+ Ok({
status: 200,
headers: [],
body: Str.toUtf8 "Hello from server",
- }
+ })
```
diff --git a/build.roc b/build.roc
index 5bf3261..ac0ad34 100644
--- a/build.roc
+++ b/build.roc
@@ -17,101 +17,101 @@ main : Task {} _
main =
cli_parser =
- Arg.Opt.maybeStr { short: "p", long: "roc", help: "Path to the roc executable. Can be just `roc` or a full path." }
- |> Arg.Cli.finish {
+ Arg.Opt.maybe_str({ short: "p", long: "roc", help: "Path to the roc executable. Can be just `roc` or a full path." })
+ |> Arg.Cli.finish({
name: "basic-webserver-builder",
version: "",
authors: ["Luke Boswell "],
description: "Generates all files needed by Roc to use this basic-cli platform.",
- }
- |> Arg.Cli.assertValid
+ })
+ |> Arg.Cli.assert_valid
- when Arg.Cli.parseOrDisplayMessage cli_parser (Arg.list! {}) is
- Ok parsed_args -> run parsed_args
- Err err_msg -> Task.err (Exit 1 err_msg)
+ when Arg.Cli.parse_or_display_message(cli_parser, Arg.list!({})) is
+ Ok(parsed_args) -> run(parsed_args)
+ Err(err_msg) -> Task.err(Exit(1, err_msg))
run : Result Str err -> Task {} _
run = \maybe_roc ->
# roc_cmd may be a path or just roc
- roc_cmd = maybe_roc |> Result.withDefault "roc"
+ roc_cmd = maybe_roc |> Result.with_default("roc")
- roc_version! roc_cmd
+ roc_version!(roc_cmd)
os_and_arch = get_os_and_arch!
- stub_lib_path = "platform/libapp.$(stub_file_extension os_and_arch)"
+ stub_lib_path = "platform/libapp.$(stub_file_extension(os_and_arch))"
- build_stub_app_lib! roc_cmd stub_lib_path
+ build_stub_app_lib!(roc_cmd, stub_lib_path)
cargo_build_host!
rust_target_folder = get_rust_target_folder!
- copy_host_lib! os_and_arch rust_target_folder
+ copy_host_lib!(os_and_arch, rust_target_folder)
- preprocess_host! roc_cmd stub_lib_path rust_target_folder
+ preprocess_host!(roc_cmd, stub_lib_path, rust_target_folder)
- info! "Successfully built platform files!"
+ info!("Successfully built platform files!")
roc_version : Str -> Task {} _
roc_version = \roc_cmd ->
- info! "Checking provided roc; executing `$(roc_cmd) version`:"
+ info!("Checking provided roc; executing `$(roc_cmd) version`:")
roc_cmd
- |> Cmd.exec ["version"]
- |> Task.mapErr! RocVersionCheckFailed
+ |> Cmd.exec(["version"])
+ |> Task.map_err!(RocVersionCheckFailed)
get_os_and_arch : Task OSAndArch _
get_os_and_arch =
- info! "Getting the native operating system and architecture..."
+ info!("Getting the native operating system and architecture...")
Env.platform
- |> Task.await convert_os_and_arch
+ |> Task.await(convert_os_and_arch)
build_stub_app_lib : Str, Str -> Task {} _
build_stub_app_lib = \roc_cmd, stub_lib_path ->
- info! "Building stubbed app shared library ..."
+ info!("Building stubbed app shared library ...")
roc_cmd
- |> Cmd.exec ["build", "--lib", "platform/libapp.roc", "--output", stub_lib_path, "--optimize"]
- |> Task.mapErr! ErrBuildingAppStub
+ |> Cmd.exec(["build", "--lib", "platform/libapp.roc", "--output", stub_lib_path, "--optimize"])
+ |> Task.map_err!(ErrBuildingAppStub)
get_rust_target_folder : Task Str _
get_rust_target_folder =
- when Env.var "CARGO_BUILD_TARGET" |> Task.result! is
- Ok target_env_var ->
- if Str.isEmpty target_env_var then
- Task.ok "target/release/"
+ when Env.var("CARGO_BUILD_TARGET") |> Task.result! is
+ Ok(target_env_var) ->
+ if Str.is_empty(target_env_var) then
+ Task.ok("target/release/")
else
- Task.ok "target/$(target_env_var)/release/"
+ Task.ok("target/$(target_env_var)/release/")
- Err e ->
- info! "Failed to get env var CARGO_BUILD_TARGET with error $(Inspect.toStr e). Assuming default CARGO_BUILD_TARGET (native)..."
+ Err(e) ->
+ info!("Failed to get env var CARGO_BUILD_TARGET with error $(Inspect.to_str(e)). Assuming default CARGO_BUILD_TARGET (native)...")
- Task.ok "target/release/"
+ Task.ok("target/release/")
cargo_build_host : Task {} _
cargo_build_host =
- info! "Building rust host ..."
+ info!("Building rust host ...")
"cargo"
- |> Cmd.exec ["build", "--release"]
- |> Task.mapErr! ErrBuildingHostBinaries
+ |> Cmd.exec(["build", "--release"])
+ |> Task.map_err!(ErrBuildingHostBinaries)
copy_host_lib : OSAndArch, Str -> Task {} _
copy_host_lib = \os_and_arch, rust_target_folder ->
host_build_path = "$(rust_target_folder)libhost.a"
- host_dest_path = "platform/$(prebuilt_static_lib_file os_and_arch)"
+ host_dest_path = "platform/$(prebuilt_static_lib_file(os_and_arch))"
- info! "Moving the prebuilt binary from $(host_build_path) to $(host_dest_path) ..."
+ info!("Moving the prebuilt binary from $(host_build_path) to $(host_dest_path) ...")
"cp"
- |> Cmd.exec [host_build_path, host_dest_path]
- |> Task.mapErr! ErrMovingPrebuiltLegacyBinary
+ |> Cmd.exec([host_build_path, host_dest_path])
+ |> Task.map_err!(ErrMovingPrebuiltLegacyBinary)
OSAndArch : [
MacosArm64,
@@ -125,11 +125,11 @@ OSAndArch : [
convert_os_and_arch : _ -> Task OSAndArch _
convert_os_and_arch = \{ os, arch } ->
when (os, arch) is
- (MACOS, AARCH64) -> Task.ok MacosArm64
- (MACOS, X64) -> Task.ok MacosX64
- (LINUX, AARCH64) -> Task.ok LinuxArm64
- (LINUX, X64) -> Task.ok LinuxX64
- _ -> Task.err (UnsupportedNative os arch)
+ (MACOS, AARCH64) -> Task.ok(MacosArm64)
+ (MACOS, X64) -> Task.ok(MacosX64)
+ (LINUX, AARCH64) -> Task.ok(LinuxArm64)
+ (LINUX, X64) -> Task.ok(LinuxX64)
+ _ -> Task.err(UnsupportedNative(os, arch))
stub_file_extension : OSAndArch -> Str
stub_file_extension = \os_and_arch ->
@@ -150,13 +150,13 @@ prebuilt_static_lib_file = \os_and_arch ->
preprocess_host : Str, Str, Str -> Task {} _
preprocess_host = \roc_cmd, stub_lib_path, rust_target_folder ->
- info! "Preprocessing surgical host ..."
+ info!("Preprocessing surgical host ...")
surgical_build_path = "$(rust_target_folder)host"
roc_cmd
- |> Cmd.exec ["preprocess-host", surgical_build_path, "platform/main.roc", stub_lib_path]
- |> Task.mapErr! ErrPreprocessingSurgicalBinary
+ |> Cmd.exec(["preprocess-host", surgical_build_path, "platform/main.roc", stub_lib_path])
+ |> Task.map_err!(ErrPreprocessingSurgicalBinary)
info : Str -> Task {} _
info = \msg ->
- Stdout.line! "\u(001b)[34mINFO:\u(001b)[0m $(msg)"
+ Stdout.line!("\u(001b)[34mINFO:\u(001b)[0m $(msg)")
diff --git a/examples/command.roc b/examples/command.roc
index 62d81be..ec026e1 100644
--- a/examples/command.roc
+++ b/examples/command.roc
@@ -7,18 +7,18 @@ import pf.Utc
Model : {}
init! : {} => Result Model _
-init! = \{} -> Ok {}
+init! = \{} -> Ok({})
respond! : Request, Model => Result Response [CmdStatusErr _]
respond! = \req, _ ->
# Log request date, method and url using echo program
- datetime = Utc.to_iso_8601 (Utc.now! {})
+ datetime = Utc.to_iso_8601(Utc.now!({}))
- try Cmd.exec! "echo" ["$(datetime) $(Inspect.toStr req.method) $(req.uri)"]
+ Cmd.exec!("echo", ["$(datetime) $(Inspect.to_str(req.method)) $(req.uri)"])?
- Ok {
+ Ok({
status: 200,
headers: [],
- body: Str.toUtf8 "Command succeeded.",
- }
+ body: Str.to_utf8("Command succeeded."),
+ })
diff --git a/examples/dir.roc b/examples/dir.roc
index 108749e..fce92da 100644
--- a/examples/dir.roc
+++ b/examples/dir.roc
@@ -12,35 +12,35 @@ init! : {} => Result Model _
init! = \{} ->
# Get current working directory
cwd =
- Env.cwd! {}
- |> Result.mapErr? \CwdUnavailable -> Exit 1 "Unable to read current working directory"
+ Env.cwd!({})
+ |> Result.map_err?(\CwdUnavailable -> Exit(1, "Unable to read current working directory"))
- try Stdout.line! "The current working directory is $(Path.display cwd)"
+ Stdout.line!("The current working directory is $(Path.display(cwd))")?
# Try to set cwd to examples
- Env.set_cwd! (Path.from_str "examples/")
- |> Result.mapErr? \InvalidCwd -> Exit 1 "Unable to set cwd to examples/"
+ Env.set_cwd!(Path.from_str("examples/"))
+ |> Result.map_err?(\InvalidCwd -> Exit(1, "Unable to set cwd to examples/"))
- try Stdout.line! "Set cwd to examples/"
+ Stdout.line!("Set cwd to examples/")?
# List contents of examples directory
paths =
- Dir.list! "./"
- |> Result.mapErr? \DirErr err -> Exit 1 "Error reading directory ./:\n\t$(Inspect.toStr err)"
+ Dir.list!("./")
+ |> Result.map_err?(\DirErr(err) -> Exit(1, "Error reading directory ./:\n\t$(Inspect.to_str(err))"))
paths
- |> List.map Path.display
- |> Str.joinWith ","
+ |> List.map(Path.display)
+ |> Str.join_with(",")
|> \paths_str -> "The paths are;\n$(paths_str)"
|> Stdout.line!
|> try
- Ok {}
+ Ok({})
respond! : Request, Model => Result Response []
respond! = \_, _ ->
- Ok {
+ Ok({
status: 200,
headers: [],
- body: Str.toUtf8 "Logged request",
- }
+ body: Str.to_utf8("Logged request"),
+ })
diff --git a/examples/echo.roc b/examples/echo.roc
index 11c3371..b1c25f9 100644
--- a/examples/echo.roc
+++ b/examples/echo.roc
@@ -7,19 +7,19 @@ import pf.Utc
Model : {}
init! : {} => Result Model []
-init! = \{} -> Ok {}
+init! = \{} -> Ok({})
respond! : Request, Model => Result Response [StdoutErr _]
respond! = \req, _ ->
# Log request datetime, method and url
- datetime = Utc.to_iso_8601 (Utc.now! {})
+ datetime = Utc.to_iso_8601(Utc.now!({}))
- try Stdout.line! "$(datetime) $(Inspect.toStr req.method) $(req.uri)"
+ Stdout.line!("$(datetime) $(Inspect.to_str(req.method)) $(req.uri)")?
# Respond with request body
- if List.isEmpty req.body then
- success []
+ if List.is_empty(req.body) then
+ success([])
else
- success req.body
+ success(req.body)
-success = \body -> Ok { status: 200, headers: [], body }
+success = \body -> Ok({ status: 200, headers: [], body })
diff --git a/examples/env.roc b/examples/env.roc
index c24671d..5de373e 100644
--- a/examples/env.roc
+++ b/examples/env.roc
@@ -10,9 +10,9 @@ init! : {} => Result Model [Exit I32 Str]_
init! = \{} ->
# Check if DEBUG environment variable is set
- when Env.var! "DEBUG" is
- Ok var if !(Str.isEmpty var) -> Ok DebugPrintMode
- _ -> Ok NonDebugMode
+ when Env.var!("DEBUG") is
+ Ok(var) if !(Str.is_empty(var)) -> Ok(DebugPrintMode)
+ _ -> Ok(NonDebugMode)
respond! : Request, Model => Result Response [ServerErr Str]_
respond! = \_, debug ->
@@ -20,19 +20,19 @@ respond! = \_, debug ->
DebugPrintMode ->
# Respond with all the current environment variables
vars : Dict Str Str
- vars = Env.dict! {}
+ vars = Env.dict!({})
# Convert the Dict to a list of key-value pairs
body =
vars
- |> Dict.toList
- |> List.map \(k, v) -> "$(k): $(v)"
- |> Str.joinWith "\n"
- |> Str.concat "\n"
- |> Str.toUtf8
+ |> Dict.to_list
+ |> List.map(\(k, v) -> "$(k): $(v)")
+ |> Str.join_with("\n")
+ |> Str.concat("\n")
+ |> Str.to_utf8
- Ok { status: 200, headers: [], body }
+ Ok({ status: 200, headers: [], body })
NonDebugMode ->
# Respond with a message that DEBUG is not set
- Ok { status: 200, headers: [], body: Str.toUtf8 "DEBUG var not set" }
+ Ok({ status: 200, headers: [], body: Str.to_utf8("DEBUG var not set") })
diff --git a/examples/error-handling.roc b/examples/error-handling.roc
index 636b4c6..78141d2 100644
--- a/examples/error-handling.roc
+++ b/examples/error-handling.roc
@@ -9,10 +9,10 @@ import pf.Env
Model : {}
init! : {} => Result Model []
-init! = \{} -> Ok {}
+init! = \{} -> Ok({})
respond! : Request, Model => Result Response [ServerErr Str]_
-respond! = \req, _ -> handle_req! req |> Result.mapErr map_app_err
+respond! = \req, _ -> handle_req!(req) |> Result.map_err(map_app_err)
AppError : [
EnvVarNotSet Str,
@@ -23,46 +23,46 @@ AppError : [
map_app_err : AppError -> [ServerErr Str]
map_app_err = \app_err ->
when app_err is
- EnvVarNotSet env_var_name -> ServerErr "Environment variable \"$(env_var_name)\" was not set."
- BadBody err -> ServerErr "Http error fetching content:\n\t$(Inspect.toStr err)"
- StdoutErr err -> ServerErr "Stdout error logging request:\n\t$(err)"
+ EnvVarNotSet(env_var_name) -> ServerErr("Environment variable \"$(env_var_name)\" was not set.")
+ BadBody(err) -> ServerErr("Http error fetching content:\n\t$(Inspect.to_str(err))")
+ StdoutErr(err) -> ServerErr("Stdout error logging request:\n\t$(err)")
# Here we use AppError to ensure all errors must be handled within our application.
handle_req! : Request => Result Response AppError
handle_req! = \req ->
# Log the date, time, method, and url to stdout
- try log_request! req
+ log_request!(req)?
# Read environment variable
- url = try read_env_var! "TARGET_URL"
+ url = read_env_var!("TARGET_URL")?
# Fetch content of url
- content = try fetch_content! url
+ content = fetch_content!(url)?
# Respond with the website content
- response_with_code! 200 content
+ response_with_code!(200, content)
log_request! : Request => Result {} [StdoutErr Str]
log_request! = \req ->
- datetime = Utc.to_iso_8601 (Utc.now! {})
+ datetime = Utc.to_iso_8601(Utc.now!({}))
- Stdout.line! "$(datetime) $(Inspect.toStr req.method) $(req.uri)"
- |> Result.mapErr \err -> StdoutErr (Inspect.toStr err)
+ Stdout.line!("$(datetime) $(Inspect.to_str(req.method)) $(req.uri)")
+ |> Result.map_err(\err -> StdoutErr(Inspect.to_str(err)))
read_env_var! : Str => Result Str [EnvVarNotSet Str]
read_env_var! = \env_var_name ->
- Env.var! env_var_name
- |> Result.mapErr \_ -> EnvVarNotSet env_var_name
+ Env.var!(env_var_name)
+ |> Result.map_err(\_ -> EnvVarNotSet(env_var_name))
fetch_content! : Str => Result Str _
fetch_content! = \url ->
- Http.get_utf8! url
+ Http.get_utf8!(url)
# Respond with the given status code and body
response_with_code! : U16, Str => Result Response *
response_with_code! = \code, body ->
- Ok {
+ Ok({
status: code,
headers: [],
- body: Str.toUtf8 body,
- }
+ body: Str.to_utf8(body),
+ })
diff --git a/examples/file-upload-form.roc b/examples/file-upload-form.roc
index 8164126..ee7b0ae 100644
--- a/examples/file-upload-form.roc
+++ b/examples/file-upload-form.roc
@@ -11,7 +11,7 @@ import pf.MultipartFormData
Model : {}
init! : {} => Result Model []
-init! = \{} -> Ok {}
+init! = \{} -> Ok({})
respond! : Request, Model => Result Response [ServerErr Str]_
respond! = \req, _ ->
@@ -36,15 +36,15 @@ respond! = \req, _ ->