Skip to content

Commit e1bca83

Browse files
upgrade to latest main -- syntax changes
1 parent 7023422 commit e1bca83

38 files changed

+412
-410
lines changed

build.roc

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
app [main!] {
2-
# TODO replace with snake_case_builtins release
3-
cli: platform "../basic-cli/platform/main.roc",
4-
weaver: "https://github.com/smores56/weaver/releases/download/0.6.0/6WdRio4quZ_3HL8cEY_vyx5mzl1xXrEv2a_c1Bswrq4.tar.br",
2+
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br",
3+
weaver: "https://github.com/smores56/weaver/releases/download/0.6.0/4GmRnyE7EFjzv6dDpebJoWWwXV285OMt4ntHIc6qvmY.tar.br",
54
}
65

76
import cli.Cmd
@@ -16,28 +15,30 @@ import weaver.Cli
1615
## run with: roc ./build.roc
1716
##
1817
main! : _ => Result {} _
19-
main! = \args ->
18+
main! = |args|
2019

2120
parsed_args =
2221
Result.on_err!(
2322
Cli.parse_or_display_message(cli_parser, args, Arg.to_os_raw),
24-
\message -> Err (Exit 1 message),
23+
|message| Err(Exit(1, message)),
2524
)?
2625

2726
run!(parsed_args)
2827

2928
cli_parser =
30-
Opt.maybe_str { short: "p", long: "roc", help: "Path to the roc executable. Can be just `roc` or a full path." }
31-
|> Cli.finish {
32-
name: "basic-webserver-builder",
33-
version: "",
34-
authors: ["Luke Boswell <https://github.com/lukewilliamboswell>"],
35-
description: "Generates all files needed by Roc to use this basic-cli platform.",
36-
}
29+
Opt.maybe_str({ short: "p", long: "roc", help: "Path to the roc executable. Can be just `roc` or a full path." })
30+
|> Cli.finish(
31+
{
32+
name: "basic-webserver-builder",
33+
version: "",
34+
authors: ["Luke Boswell <https://github.com/lukewilliamboswell>"],
35+
description: "Generates all files needed by Roc to use this basic-cli platform.",
36+
},
37+
)
3738
|> Cli.assert_valid
3839

3940
run! : Result Str err => Result {} _
40-
run! = \maybe_roc ->
41+
run! = |maybe_roc|
4142

4243
# roc_cmd may be a path or just roc
4344
roc_cmd = maybe_roc |> Result.with_default("roc")
@@ -61,30 +62,30 @@ run! = \maybe_roc ->
6162
info!("Successfully built platform files!")
6263

6364
roc_version! : Str => Result {} _
64-
roc_version! = \roc_cmd ->
65+
roc_version! = |roc_cmd|
6566

6667
info!("Checking provided roc; executing `${roc_cmd} version`:")?
6768

6869
Cmd.exec!(roc_cmd, ["version"])
6970
|> Result.map_err(RocVersionCheckFailed)
7071

7172
get_os_and_arch! : {} => Result OSAndArch _
72-
get_os_and_arch! = \{} ->
73+
get_os_and_arch! = |{}|
7374

7475
info!("Getting the native operating system and architecture...")?
7576

7677
convert_os_and_arch(Env.platform!({}))
7778

7879
build_stub_app_lib! : Str, Str => Result {} _
79-
build_stub_app_lib! = \roc_cmd, stub_lib_path ->
80+
build_stub_app_lib! = |roc_cmd, stub_lib_path|
8081

8182
info!("Building stubbed app shared library ...")?
8283

8384
Cmd.exec!(roc_cmd, ["build", "--lib", "platform/libapp.roc", "--output", stub_lib_path, "--optimize"])
8485
|> Result.map_err(ErrBuildingAppStub)
8586

8687
get_rust_target_folder! : {} => Result Str _
87-
get_rust_target_folder! = \{} ->
88+
get_rust_target_folder! = |{}|
8889
when Env.var!("CARGO_BUILD_TARGET") is
8990
Ok(target_env_var) ->
9091
if Str.is_empty(target_env_var) then
@@ -98,15 +99,15 @@ get_rust_target_folder! = \{} ->
9899
Ok("target/release/")
99100

100101
cargo_build_host! : {} => Result {} _
101-
cargo_build_host! = \{} ->
102+
cargo_build_host! = |{}|
102103

103104
info!("Building rust host ...")?
104105

105106
Cmd.exec!("cargo", ["build", "--release"])
106107
|> Result.map_err(ErrBuildingHostBinaries)
107108

108109
copy_host_lib! : OSAndArch, Str => Result {} _
109-
copy_host_lib! = \os_and_arch, rust_target_folder ->
110+
copy_host_lib! = |os_and_arch, rust_target_folder|
110111
host_build_path = "${rust_target_folder}libhost.a"
111112
host_dest_path = "platform/${prebuilt_static_lib_file(os_and_arch)}"
112113

@@ -125,7 +126,7 @@ OSAndArch : [
125126
]
126127

127128
convert_os_and_arch : _ -> Result OSAndArch _
128-
convert_os_and_arch = \{ os, arch } ->
129+
convert_os_and_arch = |{ os, arch }|
129130
when (os, arch) is
130131
(MACOS, AARCH64) -> Ok(MacosArm64)
131132
(MACOS, X64) -> Ok(MacosX64)
@@ -134,14 +135,14 @@ convert_os_and_arch = \{ os, arch } ->
134135
_ -> Err(UnsupportedNative(os, arch))
135136

136137
stub_file_extension : OSAndArch -> Str
137-
stub_file_extension = \os_and_arch ->
138+
stub_file_extension = |os_and_arch|
138139
when os_and_arch is
139140
MacosX64 | MacosArm64 -> "dylib"
140141
LinuxArm64 | LinuxX64 -> "so"
141142
WindowsX64 | WindowsArm64 -> "dll"
142143

143144
prebuilt_static_lib_file : OSAndArch -> Str
144-
prebuilt_static_lib_file = \os_and_arch ->
145+
prebuilt_static_lib_file = |os_and_arch|
145146
when os_and_arch is
146147
MacosArm64 -> "macos-arm64.a"
147148
MacosX64 -> "macos-x64.a"
@@ -151,7 +152,7 @@ prebuilt_static_lib_file = \os_and_arch ->
151152
WindowsX64 -> "windows-x64.lib"
152153

153154
preprocess_host! : Str, Str, Str => Result {} _
154-
preprocess_host! = \roc_cmd, stub_lib_path, rust_target_folder ->
155+
preprocess_host! = |roc_cmd, stub_lib_path, rust_target_folder|
155156

156157
info!("Preprocessing surgical host ...")?
157158

@@ -162,5 +163,5 @@ preprocess_host! = \roc_cmd, stub_lib_path, rust_target_folder ->
162163
|> Result.map_err(ErrPreprocessingSurgicalBinary)
163164

164165
info! : Str => Result {} _
165-
info! = \msg ->
166+
info! = |msg|
166167
Stdout.line!("\u(001b)[34mINFO:\u(001b)[0m ${msg}")

examples/command.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import pf.Utc
77
Model : {}
88

99
init! : {} => Result Model _
10-
init! = \{} -> Ok({})
10+
init! = |{}| Ok({})
1111

1212
respond! : Request, Model => Result Response [CmdStatusErr _]
13-
respond! = \req, _ ->
13+
respond! = |req, _|
1414

1515
# Log request date, method and url using echo program
1616
datetime = Utc.to_iso_8601(Utc.now!({}))

examples/dir.roc

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,32 @@ import pf.Http exposing [Request, Response]
99
Model : {}
1010

1111
init! : {} => Result Model _
12-
init! = \{} ->
12+
init! = |{}|
13+
1314
# Get current working directory
14-
cwd =
15-
Result.map_err(
16-
Env.cwd!({}),
17-
\CwdUnavailable -> Exit(1, "Unable to read current working directory"),
18-
)?
15+
cwd = Env.cwd!({}) ? |CwdUnavailable| Exit(1, "Unable to read current working directory")
1916

2017
Stdout.line!("The current working directory is ${Path.display(cwd)}")?
2118

2219
# Try to set cwd to examples
23-
Result.map_err(
24-
Env.set_cwd!(Path.from_str("examples/")),
25-
\InvalidCwd -> Exit(1, "Unable to set cwd to examples/"),
26-
)?
20+
Env.set_cwd!(Path.from_str("examples/")) ? |InvalidCwd| Exit(1, "Unable to set cwd to examples/")
2721

2822
Stdout.line!("Set cwd to examples/")?
2923
3024
# List contents of examples directory
31-
paths =
32-
Result.map_err(
33-
Dir.list!("./"),
34-
\DirErr(err) -> Exit(1, "Error reading directory ./:\n\t${Inspect.to_str(err)}"),
35-
)?
36-
37-
paths
38-
|> List.map(Path.display)
39-
|> Str.join_with(",")
40-
|> \paths_str -> "The paths are;\n${paths_str}"
41-
|> Stdout.line!
42-
|> try
25+
paths = Dir.list!("./") ? |DirErr(err)| Exit(1, "Error reading directory ./:\n\t${Inspect.to_str(err)}")
26+
27+
paths_str =
28+
paths
29+
|> List.map(Path.display)
30+
|> Str.join_with(",")
31+
32+
Stdout.line!("The paths are;\n${paths_str}")?
4333
4434
Ok({})
4535
4636
respond! : Request, Model => Result Response []
47-
respond! = \_, _ ->
37+
respond! = |_, _|
4838
Ok(
4939
{
5040
status: 200,

examples/echo.roc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import pf.Utc
77
Model : {}
88

99
init! : {} => Result Model []
10-
init! = \{} -> Ok({})
10+
init! = |{}| Ok({})
1111

1212
respond! : Request, Model => Result Response [StdoutErr _]
13-
respond! = \req, _ ->
13+
respond! = |req, _|
1414
# Log request datetime, method and url
1515
datetime = Utc.to_iso_8601(Utc.now!({}))
1616

@@ -22,4 +22,5 @@ respond! = \req, _ ->
2222
else
2323
success(req.body)
2424
25-
success = \body -> Ok({ status: 200, headers: [], body })
25+
success = |body|
26+
Ok({ status: 200, headers: [], body })

examples/env.roc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import pf.Env
77
Model : [DebugPrintMode, NonDebugMode]
88

99
init! : {} => Result Model [Exit I32 Str]_
10-
init! = \{} ->
10+
init! = |{}|
1111

1212
# Check if DEBUG environment variable is set
1313
when Env.var!("DEBUG") is
1414
Ok(var) if !(Str.is_empty(var)) -> Ok(DebugPrintMode)
1515
_ -> Ok(NonDebugMode)
1616

1717
respond! : Request, Model => Result Response [ServerErr Str]_
18-
respond! = \_, debug ->
18+
respond! = |_, debug|
1919
when debug is
2020
DebugPrintMode ->
2121
# Respond with all the current environment variables
@@ -26,7 +26,7 @@ respond! = \_, debug ->
2626
body =
2727
vars
2828
|> Dict.to_list
29-
|> List.map(\(k, v) -> "${k}: ${v}")
29+
|> List.map(|(k, v)| "${k}: ${v}")
3030
|> Str.join_with("\n")
3131
|> Str.concat("\n")
3232
|> Str.to_utf8

examples/error-handling.roc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import pf.Env
99
Model : {}
1010

1111
init! : {} => Result Model []
12-
init! = \{} -> Ok({})
12+
init! = |{}| Ok({})
1313

1414
respond! : Request, Model => Result Response [ServerErr Str]_
15-
respond! = \req, _ -> handle_req!(req) |> Result.map_err(map_app_err)
15+
respond! = |req, _| handle_req!(req) |> Result.map_err(map_app_err)
1616

1717
AppError : [
1818
EnvVarNotSet Str,
@@ -21,15 +21,15 @@ AppError : [
2121
]
2222

2323
map_app_err : AppError -> [ServerErr Str]
24-
map_app_err = \app_err ->
24+
map_app_err = |app_err|
2525
when app_err is
2626
EnvVarNotSet(env_var_name) -> ServerErr("Environment variable \"${env_var_name}\" was not set.")
2727
BadBody(err) -> ServerErr("Http error fetching content:\n\t${Inspect.to_str(err)}")
2828
StdoutErr(err) -> ServerErr("Stdout error logging request:\n\t${err}")
2929

3030
# Here we use AppError to ensure all errors must be handled within our application.
3131
handle_req! : Request => Result Response AppError
32-
handle_req! = \req ->
32+
handle_req! = |req|
3333
# Log the date, time, method, and url to stdout
3434
log_request!(req)?
3535

@@ -43,24 +43,24 @@ handle_req! = \req ->
4343
response_with_code!(200, content)
4444

4545
log_request! : Request => Result {} [StdoutErr Str]
46-
log_request! = \req ->
46+
log_request! = |req|
4747
datetime = Utc.to_iso_8601(Utc.now!({}))
4848

4949
Stdout.line!("${datetime} ${Inspect.to_str(req.method)} ${req.uri}")
50-
|> Result.map_err(\err -> StdoutErr(Inspect.to_str(err)))
50+
|> Result.map_err(|err| StdoutErr(Inspect.to_str(err)))
5151
5252
read_env_var! : Str => Result Str [EnvVarNotSet Str]
53-
read_env_var! = \env_var_name ->
53+
read_env_var! = |env_var_name|
5454
Env.var!(env_var_name)
55-
|> Result.map_err(\_ -> EnvVarNotSet(env_var_name))
55+
|> Result.map_err(|_| EnvVarNotSet(env_var_name))
5656
5757
fetch_content! : Str => Result Str _
58-
fetch_content! = \url ->
58+
fetch_content! = |url|
5959
Http.get_utf8!(url)
6060
6161
# Respond with the given status code and body
6262
response_with_code! : U16, Str => Result Response *
63-
response_with_code! = \code, body ->
63+
response_with_code! = |code, body|
6464
Ok(
6565
{
6666
status: code,

examples/file-upload-form.roc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, init!, respond!] {
22
pf: platform "../platform/main.roc",
3-
utils: "https://github.com/quelgar/roc-utils/releases/download/v0.2.0/Ln38Q74rVeU6KAlT8dsB6nyKlUoD-O-43H41nCJ52Yk.tar.br",
3+
utils: "https://github.com/lukewilliamboswell/roc-utils/releases/download/0.3.0/w1rWVzjiBSrvc1VHPNX10o0bHI7rmBdT36hFQ0f5R_w.tar.br",
44
}
55

66
import utils.Base64
@@ -11,10 +11,10 @@ import pf.MultipartFormData
1111
Model : {}
1212

1313
init! : {} => Result Model []
14-
init! = \{} -> Ok({})
14+
init! = |{}| Ok({})
1515

1616
respond! : Request, Model => Result Response [ServerErr Str]_
17-
respond! = \req, _ ->
17+
respond! = |req, _|
1818
if req.method == GET then
1919
Ok(
2020
{
@@ -46,7 +46,7 @@ respond! = \req, _ ->
4646
},
4747
)
4848
else if req.method == POST then
49-
page = \src ->
49+
page = |src|
5050
Str.to_utf8(
5151
"""
5252
<!DOCTYPE html>

examples/file.roc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Model : Str
99

1010
# We only read the file once in `init`. If that fails, we don't launch the server.
1111
init! : {} => Result Model [Exit I32 Str]_
12-
init! = \{} ->
12+
init! = |{}|
1313
# Read the contents of examples/file.roc
1414
File.read_utf8!("examples/file.roc")
15-
|> Result.map_ok(\contents -> "Source code of current program:\n\n${contents}")
15+
|> Result.map_ok(|contents| "Source code of current program:\n\n${contents}")
1616
|> Result.map_err(
17-
\err ->
17+
|err|
1818
when err is
1919
FileReadErr(path, file_err) ->
2020
Exit(
@@ -30,6 +30,6 @@ init! = \{} ->
3030
)
3131

3232
respond! : Request, Model => Result Response [ServerErr Str]_
33-
respond! = \_, model ->
33+
respond! = |_, model|
3434
# If the server launched, the model contains the file content.
3535
Ok({ status: 200, headers: [], body: Str.to_utf8(model) })

examples/hello-web.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Model : {}
1111
# generate css by running `tailwindcss`,...
1212
# In this case we don't have anything to initialize, so it is just `Ok {}`.
1313
init! : {} => Result Model []
14-
init! = \{} -> Ok({})
14+
init! = |{}| Ok({})
1515

1616
respond! : Request, Model => Result Response [ServerErr Str]_
17-
respond! = \req, _ ->
17+
respond! = |req, _|
1818
# Log request datetime, method and url
1919
datetime = Utc.to_iso_8601(Utc.now!({}))
2020

0 commit comments

Comments
 (0)