From b3706f8956d54aa9a93112e2dc3ffaf9b7e8fa40 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Mon, 20 Jan 2025 11:20:27 +1100 Subject: [PATCH 1/2] WIP convert to zero args --- build.roc | 18 ++++++++-------- examples/command.roc | 25 +++++++++++----------- examples/countdown.roc | 8 +++---- examples/dir.roc | 4 ++-- examples/echo.roc | 20 +++++++++--------- examples/file-mixed.roc | 10 ++++----- examples/file-read.roc | 8 +++---- examples/form.roc | 4 ++-- examples/piping.roc | 4 ++-- examples/sqlite.roc | 2 +- examples/stdin.roc | 8 +++---- examples/task-list.roc | 2 +- examples/tcp-client.roc | 10 ++++----- examples/temp-dir.roc | 2 +- examples/time.roc | 4 ++-- platform/Cmd.roc | 2 +- platform/Env.roc | 40 +++++++++++++++++------------------ platform/EnvDecoding.roc | 40 +++++++++++++++++------------------ platform/Host.roc | 32 ++++++++++++++-------------- platform/Http.roc | 2 +- platform/InternalDateTime.roc | 10 ++++----- platform/Locale.roc | 10 ++++----- platform/Path.roc | 10 ++++----- platform/Sqlite.roc | 4 ++-- platform/Stdin.roc | 18 ++++++++-------- platform/Tty.roc | 12 +++++------ platform/Url.roc | 13 ++++++------ platform/Utc.roc | 10 ++++----- platform/main.roc | 2 +- 29 files changed, 167 insertions(+), 167 deletions(-) diff --git a/build.roc b/build.roc index 4c03c147..aea93ba0 100755 --- a/build.roc +++ b/build.roc @@ -15,16 +15,16 @@ import cli.Env main! : _ => Result {} _ main! = |_args| - roc_cmd = Env.var!("ROC") |> Result.with_default("roc") + roc_cmd = Env.var!("ROC") ?? "roc" debug_mode = when Env.var!("DEBUG") is - Ok(str) if !(Str.is_empty(str)) -> Debug + Ok(str) if !Str.is_empty(str) -> Debug _ -> Release roc_version!(roc_cmd)? - os_and_arch = get_os_and_arch!({})? + os_and_arch = get_os_and_arch!()? stub_lib_path = "platform/libapp.${stub_file_extension(os_and_arch)}" @@ -40,7 +40,7 @@ main! = |_args| info!("Successfully built platform files!")? - Ok({}) + Ok() roc_version! : Str => Result {} _ roc_version! = |roc_cmd| @@ -49,11 +49,11 @@ roc_version! = |roc_cmd| Cmd.exec!(roc_cmd, ["version"]) |> Result.map_err(RocVersionCheckFailed) -get_os_and_arch! : {} => Result OSAndArch _ -get_os_and_arch! = |{}| +get_os_and_arch! : () => Result OSAndArch _ +get_os_and_arch! = || info!("Getting the native operating system and architecture ...")? - convert_os_and_arch!(Env.platform!({})) + convert_os_and_arch!(Env.platform!()) OSAndArch : [ MacosArm64, @@ -117,7 +117,7 @@ get_rust_target_folder! = |debug_mode| cargo_build_host! : [Debug, Release] => Result {} _ cargo_build_host! = |debug_mode| - cargo_build_args! = |{}| + cargo_build_args! = || when debug_mode is Debug -> info!("Building rust host in debug mode...")? @@ -127,7 +127,7 @@ cargo_build_host! = |debug_mode| info!("Building rust host ...")? Ok(["build", "--release"]) - args = cargo_build_args!({})? + args = cargo_build_args!()? Cmd.exec!("cargo", args) |> Result.map_err(ErrBuildingHostBinaries) diff --git a/examples/command.roc b/examples/command.roc index f1611c41..6c5676f9 100644 --- a/examples/command.roc +++ b/examples/command.roc @@ -6,21 +6,22 @@ import pf.Stdout import pf.Cmd main! = |_args| - status_example!({})? + status_example!()? - output_example!({})? + output_example!()? - exec_example!({})? + exec_example!()? - Ok({}) + Ok() -exec_example! : {} => Result {} _ -exec_example! = |{}| Cmd.exec!("echo", ["EXEC"]) +exec_example! : () => Result {} _ +exec_example! = || + Cmd.exec!("echo", ["EXEC"]) # Run "env" with verbose option, clear all environment variables, and pass in # "FOO" and "BAZ". -status_example! : {} => Result {} _ -status_example! = |{}| +status_example! : () => Result {} _ +status_example! = || result = Cmd.new("env") |> Cmd.arg("-v") @@ -29,14 +30,14 @@ status_example! = |{}| |> Cmd.status! when result is - Ok(exit_code) if exit_code == 0 -> Ok({}) + Ok(exit_code) if exit_code == 0 -> Ok() Ok(exit_code) -> Stdout.line!("Child exited with non-zero code: ${Num.to_str(exit_code)}") Err(err) -> Stdout.line!("Error executing command: ${Inspect.to_str(err)}") # Run "env" with verbose option, clear all environment variables, and pass in # only as an environment variable "FOO" -output_example! : {} => Result {} _ -output_example! = |{}| +output_example! : () => Result {} _ +output_example! = || output = Cmd.new("env") @@ -45,6 +46,6 @@ output_example! = |{}| |> Cmd.args(["-v"]) |> Cmd.output! - msg = Str.from_utf8(output.stdout) |> Result.with_default("Failed to decode stdout") + msg = Str.from_utf8(output.stdout) ?? "Failed to decode stdout" Stdout.write!(msg) diff --git a/examples/countdown.roc b/examples/countdown.roc index 68895cda..9ba2b13b 100644 --- a/examples/countdown.roc +++ b/examples/countdown.roc @@ -7,14 +7,14 @@ import pf.Stdout main! = |_args| Stdout.line!("\nLet's count down from 3 together - all you have to do is press .")? - _ = Stdin.line!({}) + _ = Stdin.line!() tick!(3) tick! = |n| if n == 0 then Stdout.line!("๐ŸŽ‰ SURPRISE! Happy Birthday! ๐ŸŽ‚")? - Ok({}) + Ok() else - Stdout.line!("${Num.to_str n}...")? - _ = Stdin.line!({}) + Stdout.line!("${Num.to_str(n)}...")? + _ = Stdin.line!() tick!(n - 1) diff --git a/examples/dir.roc b/examples/dir.roc index a75fd026..3aebe6b3 100644 --- a/examples/dir.roc +++ b/examples/dir.roc @@ -28,7 +28,7 @@ main! = |_args| # Try to create a directory without a parent (should fail, ignore error) when Dir.create!("dirExampleD/child") is - Ok({}) -> {} + Ok() -> {} Err(_) -> {} # Delete an empty directory @@ -39,4 +39,4 @@ main! = |_args| Stdout.line!("Success!")? - Ok({}) + Ok() diff --git a/examples/echo.roc b/examples/echo.roc index 4cbb27b7..2d50491c 100644 --- a/examples/echo.roc +++ b/examples/echo.roc @@ -7,22 +7,22 @@ import pf.Stdout main! = |_args| Stdout.line!("Shout into this cave and hear the echo!")? - tick!({}) + tick!() -tick! : {} => Result {} [StdoutErr _] -tick! = |{}| - when Stdin.line!({}) is +tick! : () => Result {} [StdoutErr _] +tick! = || + when Stdin.line!() is Ok(str) -> Stdout.line!(echo(str))? - tick!({}) + tick!() Err(EndOfFile) -> Stdout.line!(echo("Received end of input (EOF)."))? - Ok({}) + Ok() Err(StdinErr(err)) -> Stdout.line!(echo("Unable to read input ${Inspect.to_str(err)}"))? - Ok({}) + Ok() echo : Str -> Str echo = |shout| @@ -32,10 +32,10 @@ echo = |shout| |> Str.to_utf8 |> List.map_with_index( |_, i| - length = (List.len(Str.to_utf8(shout)) - i) - phrase = (List.split_at(Str.to_utf8(shout), length)).before + length = List.len(Str.to_utf8(shout)) - i + { before: phrase} = List.split_at(Str.to_utf8(shout), length) - List.concat(silence((if i == 0 then 2 * length else length)), phrase), + List.concat(silence(if i == 0 then 2 * length else length), phrase), ) |> List.join |> Str.from_utf8 diff --git a/examples/file-mixed.roc b/examples/file-mixed.roc index c78e0e74..f23c0922 100644 --- a/examples/file-mixed.roc +++ b/examples/file-mixed.roc @@ -11,9 +11,9 @@ import pf.Dir out_txt_path = "out.txt" -task! = |{}| +task! = || - cwd_str = Path.display(Env.cwd!({})?) + cwd_str = Path.display(Env.cwd!()?) Stdout.line!("cwd: ${cwd_str}")? @@ -31,11 +31,11 @@ task! = |{}| Stdout.line!("I read the file back. Its contents: \"${contents}\"")? - Ok({}) + Ok() main! = |_args| - when task!({}) is - Ok({}) -> Stdout.line!("Successfully wrote a string to out.txt") + when task!() is + Ok() -> Stdout.line!("Successfully wrote a string to out.txt") Err(err) -> msg = when err is diff --git a/examples/file-read.roc b/examples/file-read.roc index c0e93de6..ffe1b85a 100644 --- a/examples/file-read.roc +++ b/examples/file-read.roc @@ -7,7 +7,7 @@ import pf.File main! = |_args| - run!({}) + run!() ? |err| msg = when err is @@ -19,11 +19,11 @@ main! = |_args| Exit(1, "unable to read file: ${msg}") # non-zero exit code to indicate failure - Ok({}) + Ok() -run! = |{}| +run! = || file_name = "LICENSE" contents = File.read_utf8!(file_name)? lines = Str.split_on(contents, "\n") - Stdout.line!(Str.concat("First line of ${file_name}: ", (List.first(lines) |> Result.with_default("err")))) + Stdout.line!(Str.concat("First line of ${file_name}: ", List.first(lines) ?? "err")) diff --git a/examples/form.roc b/examples/form.roc index c93ff7d0..2f65967d 100644 --- a/examples/form.roc +++ b/examples/form.roc @@ -9,10 +9,10 @@ main! = |_args| Stdout.line!("What's your first name?")? - first = Stdin.line!({})? + first = Stdin.line!()? Stdout.line!("What's your last name?")? - last = Stdin.line!({})? + last = Stdin.line!()? Stdout.line!("Hi, ${first} ${last}! ๐Ÿ‘‹") diff --git a/examples/piping.roc b/examples/piping.roc index f92b2200..9ecd398e 100644 --- a/examples/piping.roc +++ b/examples/piping.roc @@ -11,6 +11,6 @@ main! = |_args| Stdout.line!("I read ${Num.to_str(lines)} lines from stdin.") count! = |n| - when Stdin.line!({}) is - Ok(_) -> count!((n + 1)) + when Stdin.line!() is + Ok(_) -> count!(n + 1) Err(_) -> n diff --git a/examples/sqlite.roc b/examples/sqlite.roc index 20e613fa..5791c9c0 100644 --- a/examples/sqlite.roc +++ b/examples/sqlite.roc @@ -29,7 +29,7 @@ main! = |_args| Stdout.line!("\tid: ${id}, task: ${task}"), )? - Ok({}) + Ok() query_todos_by_status! = |db_path, status| Sqlite.query_many!( diff --git a/examples/stdin.roc b/examples/stdin.roc index 29e82d6e..4cbf3e8d 100644 --- a/examples/stdin.roc +++ b/examples/stdin.roc @@ -9,7 +9,7 @@ import pf.Stdin main! = |_args| Stdout.line!("Enter a series of number characters (0-9):")? - number_bytes = take_number_bytes!({})? + number_bytes = take_number_bytes!()? if List.is_empty(number_bytes) then Stderr.line!("Expected a series of number characters (0-9)") @@ -21,9 +21,9 @@ main! = |_args| Err(_) -> Stderr.line!("Error, bad utf8") -take_number_bytes! : {} => Result (List U8) _ -take_number_bytes! = |{}| - bytes_read = Stdin.bytes!({})? +take_number_bytes! : () => Result (List U8) _ +take_number_bytes! = || + bytes_read = Stdin.bytes!()? number_bytes = List.walk( diff --git a/examples/task-list.roc b/examples/task-list.roc index 2233dc3a..1a4b8bc5 100644 --- a/examples/task-list.roc +++ b/examples/task-list.roc @@ -11,7 +11,7 @@ main! = |_args| print! : List Str => Result {} _ print! = |authors| when authors is - [] -> Ok({}) + [] -> Ok() [author, .. as rest] -> Stdout.line!(author)? print!(rest) diff --git a/examples/tcp-client.roc b/examples/tcp-client.roc index 9c67d4b4..293c9cb2 100644 --- a/examples/tcp-client.roc +++ b/examples/tcp-client.roc @@ -8,8 +8,8 @@ import pf.Stderr # To run this example: check the README.md in this folder main! = |_args| - when run!({}) is - Ok({}) -> Ok({}) + when run!() is + Ok() -> Ok() Err(err) -> handle_err!(err) handle_err! : []_ => Result {} _ @@ -42,8 +42,8 @@ handle_err! = |error| other -> Stderr.line!("Got other error: ${Inspect.to_str(other)}") -run! : {} => Result {} _ -run! = |{}| +run! : () => Result {} _ +run! = || stream = Tcp.connect!("127.0.0.1", 8085)? @@ -58,7 +58,7 @@ tick! : Tcp.Stream => Result {} _ tick! = |stream| Stdout.write!("> ")? - out_msg = Stdin.line!({})? + out_msg = Stdin.line!()? Tcp.write_utf8!(stream, "${out_msg}\n")? diff --git a/examples/temp-dir.roc b/examples/temp-dir.roc index 270b705d..c49d0c47 100644 --- a/examples/temp-dir.roc +++ b/examples/temp-dir.roc @@ -12,7 +12,7 @@ import pf.Path ## for example: `roc build examples/temp-dir.roc --linker=legacy` main! = |_args| - temp_dir_str = Path.display(Env.temp_dir!({})) + temp_dir_str = Path.display(Env.temp_dir!()) Stdout.line!("The temp dir path is ${temp_dir_str}") |> Result.map_err(|err| Exit(1, "Failed to print temp dir:\n\t${Inspect.to_str(err)}")) diff --git a/examples/time.roc b/examples/time.roc index 13cbcaf1..04a201a5 100644 --- a/examples/time.roc +++ b/examples/time.roc @@ -7,11 +7,11 @@ import pf.Sleep # To run this example: check the README.md in this folder main! = |_args| - start = Utc.now!({}) + start = Utc.now!() Sleep.millis!(1500) - finish = Utc.now!({}) + finish = Utc.now!() duration = Num.to_str(Utc.delta_as_nanos(start, finish)) diff --git a/platform/Cmd.roc b/platform/Cmd.roc index 16b8e8dc..ab8ed8d2 100644 --- a/platform/Cmd.roc +++ b/platform/Cmd.roc @@ -131,6 +131,6 @@ exec! = |program, arguments| |> status!? if exit_code == 0i32 then - Ok({}) + Ok() else Err(CmdStatusErr(Other("Non-zero exit code ${Num.to_str(exit_code)}"))) diff --git a/platform/Env.roc b/platform/Env.roc index 83ddb87d..c7aa46f9 100644 --- a/platform/Env.roc +++ b/platform/Env.roc @@ -16,9 +16,9 @@ import Host ## Reads the [current working directory](https://en.wikipedia.org/wiki/Working_directory) ## from the environment. File operations on relative [Path]s are relative to this directory. -cwd! : {} => Result Path [CwdUnavailable] -cwd! = |{}| - bytes = Host.cwd!({}) |> Result.with_default([]) +cwd! : () => Result Path [CwdUnavailable] +cwd! = || + bytes = Host.cwd!() ?? [] if List.is_empty(bytes) then Err(CwdUnavailable) @@ -31,14 +31,14 @@ cwd! = |{}| set_cwd! : Path => Result {} [InvalidCwd] set_cwd! = |path| Host.set_cwd!(InternalPath.to_bytes(path)) - |> Result.map_err(|{}| InvalidCwd) + |> Result.map_err(|| InvalidCwd) ## Gets the path to the currently-running executable. -exe_path! : {} => Result Path [ExePathUnavailable] -exe_path! = |{}| - when Host.exe_path!({}) is +exe_path! : () => Result Path [ExePathUnavailable] +exe_path! = || + when Host.exe_path!() is Ok(bytes) -> Ok(InternalPath.from_os_bytes(bytes)) - Err({}) -> Err(ExePathUnavailable) + Err() -> Err(ExePathUnavailable) ## Reads the given environment variable. ## @@ -47,7 +47,7 @@ exe_path! = |{}| var! : Str => Result Str [VarNotFound] var! = |name| Host.env_var!(name) - |> Result.map_err(|{}| VarNotFound) + |> Result.map_err(|| VarNotFound) ## Reads the given environment variable and attempts to decode it. ## @@ -78,19 +78,19 @@ var! = |name| decode! : Str => Result val [VarNotFound, DecodeErr DecodeError] where val implements Decoding decode! = |name| when Host.env_var!(name) is - Err({}) -> Err(VarNotFound) + Err() -> Err(VarNotFound) Ok(var_str) -> Str.to_utf8(var_str) - |> Decode.from_bytes(EnvDecoding.format({})) + |> Decode.from_bytes(EnvDecoding.format()) |> Result.map_err(|_| DecodeErr(TooShort)) ## Reads all the process's environment variables into a [Dict]. ## ## If any key or value contains invalid Unicode, the [Unicode replacement character](https://unicode.org/glossary/#replacement_character) ## will be used in place of any parts of keys or values that are invalid Unicode. -dict! : {} => Dict Str Str -dict! = |{}| - Host.env_dict!({}) +dict! : () => Dict Str Str +dict! = || + Host.env_dict!() |> Dict.from_list # ## Walks over the process's environment variables as key-value arguments to the walking function. @@ -135,10 +135,10 @@ OS : [LINUX, MACOS, WINDOWS, OTHER Str] ## ## Note these values are constants from when the platform is built. ## -platform! : {} => { arch : ARCH, os : OS } -platform! = |{}| +platform! : () => { arch : ARCH, os : OS } +platform! = || - from_rust = Host.current_arch_os!({}) + from_rust = Host.current_arch_os!() arch = when from_rust.arch is @@ -166,7 +166,7 @@ platform! = |{}| ## to create a uniquely named file. Creating a file or directory with a fixed or predictable name may ## result in โ€œinsecure temporary fileโ€ security vulnerabilities. ## -temp_dir! : {} => Path -temp_dir! = |{}| - Host.temp_dir!({}) +temp_dir! : () => Path +temp_dir! = || + Host.temp_dir!() |> InternalPath.from_os_bytes diff --git a/platform/EnvDecoding.roc b/platform/EnvDecoding.roc index 4c710804..153cd59a 100644 --- a/platform/EnvDecoding.roc +++ b/platform/EnvDecoding.roc @@ -27,7 +27,7 @@ EnvFormat := {} implements [ ] format : {} -> EnvFormat -format = |{}| @EnvFormat({}) +format = || @EnvFormat() decode_bytes_to_num = |bytes, transformer| when Str.from_utf8(bytes) is @@ -38,22 +38,22 @@ decode_bytes_to_num = |bytes, transformer| Err(_) -> { result: Err(TooShort), rest: bytes } -env_u8 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u8)) -env_u16 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u16)) -env_u32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u32)) -env_u64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u64)) -env_u128 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u128)) -env_i8 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i8)) -env_i16 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i16)) -env_i32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i32)) -env_i64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i64)) -env_i128 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i128)) -env_f32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_f32)) -env_f64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_f64)) -env_dec = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_dec)) +env_u8 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u8)) +env_u16 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u16)) +env_u32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u32)) +env_u64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u64)) +env_u128 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u128)) +env_i8 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i8)) +env_i16 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i16)) +env_i32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i32)) +env_i64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i64)) +env_i128 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i128)) +env_f32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_f32)) +env_f64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_f64)) +env_dec = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_dec)) env_bool = Decode.custom( - |bytes, @EnvFormat({})| + |bytes, @EnvFormat()| when Str.from_utf8(bytes) is Ok("true") -> { result: Ok(Bool.true), rest: [] } Ok("false") -> { result: Ok(Bool.false), rest: [] } @@ -61,7 +61,7 @@ env_bool = Decode.custom( ) env_string = Decode.custom( - |bytes, @EnvFormat({})| + |bytes, @EnvFormat()| when Str.from_utf8(bytes) is Ok(s) -> { result: Ok(s), rest: [] } Err(_) -> { result: Err(TooShort), rest: bytes }, @@ -69,7 +69,7 @@ env_string = Decode.custom( env_list = |decode_elem| Decode.custom( - |bytes, @EnvFormat({})| + |bytes, @EnvFormat()| # Per our supported methods of decoding, this is either a list of strings or # a list of numbers; in either case, the list of bytes must be Utf-8 # decodable. So just parse it as a list of strings and pass each chunk to @@ -84,7 +84,7 @@ env_list = |decode_elem| Err(NotFound) -> { to_parse: all_bytes, remainder: None } - when Decode.decode_with(to_parse, decode_elem, @EnvFormat({})) is + when Decode.decode_with(to_parse, decode_elem, @EnvFormat()) is { result, rest } -> when result is Ok(val) -> @@ -106,7 +106,7 @@ env_list = |decode_elem| env_record : _, (_, _ -> [Keep (Decoder _ _), Skip]), (_, _ -> _) -> Decoder _ _ env_record = |_initialState, _stepField, _finalizer| Decode.custom( - |bytes, @EnvFormat({})| + |bytes, @EnvFormat()| { result: Err(TooShort), rest: bytes }, ) @@ -116,6 +116,6 @@ env_record = |_initialState, _stepField, _finalizer| env_tuple : _, (_, _ -> [Next (Decoder _ _), TooLong]), (_ -> _) -> Decoder _ _ env_tuple = |_initialState, _stepElem, _finalizer| Decode.custom( - |bytes, @EnvFormat({})| + |bytes, @EnvFormat()| { result: Err(TooShort), rest: bytes }, ) diff --git a/platform/Host.roc b/platform/Host.roc index a12791ea..7384a206 100644 --- a/platform/Host.roc +++ b/platform/Host.roc @@ -80,17 +80,17 @@ dir_delete_all! : List U8 => Result {} InternalIOErr.IOErrFromHost hard_link! : List U8 => Result {} InternalIOErr.IOErrFromHost path_type! : List U8 => Result InternalPath.InternalPathType InternalIOErr.IOErrFromHost -cwd! : {} => Result (List U8) {} -temp_dir! : {} => List U8 +cwd! : () => Result (List U8) {} +temp_dir! : () => List U8 # STDIO stdout_line! : Str => Result {} InternalIOErr.IOErrFromHost stdout_write! : Str => Result {} InternalIOErr.IOErrFromHost stderr_line! : Str => Result {} InternalIOErr.IOErrFromHost stderr_write! : Str => Result {} InternalIOErr.IOErrFromHost -stdin_line! : {} => Result Str InternalIOErr.IOErrFromHost -stdin_bytes! : {} => Result (List U8) InternalIOErr.IOErrFromHost -stdin_read_to_end! : {} => Result (List U8) InternalIOErr.IOErrFromHost +stdin_line! : () => Result Str InternalIOErr.IOErrFromHost +stdin_bytes! : () => Result (List U8) InternalIOErr.IOErrFromHost +stdin_read_to_end! : () => Result (List U8) InternalIOErr.IOErrFromHost # TCP send_request! : InternalHttp.RequestToAndFromHost => InternalHttp.ResponseToAndFromHost @@ -105,25 +105,25 @@ tcp_write! : TcpStream, List U8 => Result {} Str # SQLITE sqlite_prepare! : Str, Str => Result (Box {}) InternalSqlite.SqliteError sqlite_bind! : Box {}, List InternalSqlite.SqliteBindings => Result {} InternalSqlite.SqliteError -sqlite_columns! : Box {} => List Str +sqlite_columns! : Box () => List Str sqlite_column_value! : Box {}, U64 => Result InternalSqlite.SqliteValue InternalSqlite.SqliteError -sqlite_step! : Box {} => Result InternalSqlite.SqliteState InternalSqlite.SqliteError -sqlite_reset! : Box {} => Result {} InternalSqlite.SqliteError +sqlite_step! : Box () => Result InternalSqlite.SqliteState InternalSqlite.SqliteError +sqlite_reset! : Box () => Result {} InternalSqlite.SqliteError # OTHERS -current_arch_os! : {} => { arch : Str, os : Str } +current_arch_os! : () => { arch : Str, os : Str } -get_locale! : {} => Result Str {} -get_locales! : {} => List Str +get_locale! : () => Result Str {} +get_locales! : () => List Str -posix_time! : {} => U128 # TODO why is this a U128 but then getting converted to a I128 in Utc.roc? +posix_time! : () => U128 # TODO why is this a U128 but then getting converted to a I128 in Utc.roc? sleep_millis! : U64 => {} -tty_mode_canonical! : {} => {} -tty_mode_raw! : {} => {} +tty_mode_canonical! : () => {} +tty_mode_raw! : () => {} -env_dict! : {} => List (Str, Str) +env_dict! : () => List (Str, Str) env_var! : Str => Result Str {} -exe_path! : {} => Result (List U8) {} +exe_path! : () => Result (List U8) {} set_cwd! : List U8 => Result {} {} diff --git a/platform/Http.roc b/platform/Http.roc index f99d6ed8..9aae4e40 100644 --- a/platform/Http.roc +++ b/platform/Http.roc @@ -55,7 +55,7 @@ header = |(name, value)| { name, value } ## ## ``` ## # Prints out the HTML of the Roc-lang website. -## response = || +## response = or ## Http.send!({ Http.default_request & url: "https://www.roc-lang.org" })? ## ## diff --git a/platform/InternalDateTime.roc b/platform/InternalDateTime.roc index 49dc0e03..17af6dc0 100644 --- a/platform/InternalDateTime.roc +++ b/platform/InternalDateTime.roc @@ -55,14 +55,14 @@ is_leap_year = |year| && # divided evenly by 4 unless... ( (year % 100 != 0) - || # divided by 100 not a leap year + or # divided by 100 not a leap year (year % 400 == 0) # expecpt when also divisible by 400 ) expect is_leap_year(2000) expect is_leap_year(2012) -expect !(is_leap_year(1900)) -expect !(is_leap_year(2015)) +expect !is_leap_year(1900) +expect !is_leap_year(2015) expect List.map([2023, 1988, 1992, 1996], is_leap_year) == [Bool.false, Bool.true, Bool.true, Bool.true] expect List.map([1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600], is_leap_year) == [Bool.false, Bool.false, Bool.false, Bool.false, Bool.false, Bool.false, Bool.false, Bool.false] @@ -116,9 +116,9 @@ epoch_millis_to_datetimeHelp = |current| count_days_in_month = days_in_month(current.year, current.month) count_days_in_prev_month = if current.month == 1 then - days_in_month((current.year - 1), 12) + days_in_month(current.year - 1, 12) else - days_in_month(current.year, (current.month - 1)) + days_in_month(current.year, current.month - 1) if current.day < 1 then epoch_millis_to_datetimeHelp( diff --git a/platform/Locale.roc b/platform/Locale.roc index 9c32fe72..2cb1647d 100644 --- a/platform/Locale.roc +++ b/platform/Locale.roc @@ -8,13 +8,13 @@ import Host ## Returns the most preferred locale for the system or application, or `NotAvailable` if the locale could not be obtained. ## ## The returned [Str] is a BCP 47 language tag, like `en-US` or `fr-CA`. -get! : {} => Result Str [NotAvailable] -get! = |{}| - Host.get_locale!({}) - |> Result.map_err(|{}| NotAvailable) +get! : () => Result Str [NotAvailable] +get! = || + Host.get_locale!() + |> Result.map_err(|| NotAvailable) ## Returns the preferred locales for the system or application. ## ## The returned [Str] are BCP 47 language tags, like `en-US` or `fr-CA`. -all! : {} => List Str +all! : () => List Str all! = Host.get_locales! diff --git a/platform/Path.roc b/platform/Path.roc index 8096e06f..330da5c7 100644 --- a/platform/Path.roc +++ b/platform/Path.roc @@ -184,7 +184,7 @@ display = |path| is_dir! : Path => Result Bool [PathErr IOErr] is_dir! = |path| res = type!(path)? - Ok((res == IsDir)) + Ok(res == IsDir) ## Returns true if the path exists on disk and is pointing at a regular file. ## Returns `Ok false` if the path exists and it is not a file. If the path does not exist, @@ -196,7 +196,7 @@ is_dir! = |path| is_file! : Path => Result Bool [PathErr IOErr] is_file! = |path| res = type!(path)? - Ok((res == IsFile)) + Ok(res == IsFile) ## Returns true if the path exists on disk and is pointing at a symbolic link. ## Returns `Ok false` if the path exists and it is not a symbolic link. If the path does not exist, @@ -208,7 +208,7 @@ is_file! = |path| is_sym_link! : Path => Result Bool [PathErr IOErr] is_sym_link! = |path| res = type!(path)? - Ok((res == IsSymLink)) + Ok(res == IsSymLink) ## Return the type of the path if the path exists on disk. ## @@ -246,7 +246,7 @@ with_extension = |path, extension| Err(NotFound) -> bytes before_dot - |> List.reserve((Str.count_utf8_bytes(extension) |> Num.int_cast |> Num.add_saturated(1))) + |> List.reserve(Str.count_utf8_bytes(extension) |> Num.int_cast |> Num.add_saturated(1)) |> List.append(Num.to_u8('.')) |> List.concat(Str.to_utf8(extension)) |> ArbitraryBytes @@ -259,7 +259,7 @@ with_extension = |path, extension| Err(NotFound) -> str before_dot - |> Str.reserve((Str.count_utf8_bytes(extension) |> Num.add_saturated(1))) + |> Str.reserve(Str.count_utf8_bytes(extension) |> Num.add_saturated(1)) |> Str.concat(".") |> Str.concat(extension) |> FromStr diff --git a/platform/Sqlite.roc b/platform/Sqlite.roc index 661dd209..aa54b374 100644 --- a/platform/Sqlite.roc +++ b/platform/Sqlite.roc @@ -239,7 +239,7 @@ execute_prepared! = |{ stmt, bindings }| try(reset!, stmt) when res is Ok(Done) -> - Ok({}) + Ok() Ok(Row) -> Err(UnhandledRows) @@ -670,7 +670,7 @@ internal_to_external_error = |{ code, message }| # internal use only code_from_i64 : I64 -> ErrCode code_from_i64 = |code| - if code == 1 || code == 0 then + if code == 1 or code == 0 then Error else if code == 2 then Internal diff --git a/platform/Stdin.roc b/platform/Stdin.roc index af29c2b8..2e664de6 100644 --- a/platform/Stdin.roc +++ b/platform/Stdin.roc @@ -53,9 +53,9 @@ handle_err = |{ tag, msg }| ## (e.g. because the user pressed Enter in the terminal), so using it can result in the appearance of the ## programming having gotten stuck. It's often helpful to print a prompt first, so ## the user knows it's necessary to enter something before the program will continue. -line! : {} => Result Str [EndOfFile, StdinErr IOErr] -line! = |{}| - Host.stdin_line!({}) +line! : () => Result Str [EndOfFile, StdinErr IOErr] +line! = || + Host.stdin_line!() |> Result.map_err(handle_err) ## Read bytes from [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). @@ -64,15 +64,15 @@ line! = |{}| ## > This is typically used in combintation with [Tty.enable_raw_mode!], ## which disables defaults terminal bevahiour and allows reading input ## without buffering until Enter key is pressed. -bytes! : {} => Result (List U8) [EndOfFile, StdinErr IOErr] -bytes! = |{}| - Host.stdin_bytes!({}) +bytes! : () => Result (List U8) [EndOfFile, StdinErr IOErr] +bytes! = || + Host.stdin_bytes!() |> Result.map_err(handle_err) ## Read all bytes from [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) until EOF in this source. -read_to_end! : {} => Result (List U8) [StdinErr IOErr] -read_to_end! = |{}| - Host.stdin_read_to_end!({}) +read_to_end! : () => Result (List U8) [StdinErr IOErr] +read_to_end! = || + Host.stdin_read_to_end!() |> Result.map_err( |{ tag, msg }| when tag is diff --git a/platform/Tty.roc b/platform/Tty.roc index 741ebe5c..8d6d33d4 100644 --- a/platform/Tty.roc +++ b/platform/Tty.roc @@ -19,14 +19,14 @@ import Host ## ## Note: we plan on moving this function away from basic-cli in the future, see github.com/roc-lang/basic-cli/issues/73 ## -enable_raw_mode! : {} => {} -enable_raw_mode! = |{}| - Host.tty_mode_raw!({}) +enable_raw_mode! : () => {} +enable_raw_mode! = || + Host.tty_mode_raw!() ## Revert terminal to default behaviour ## ## Note: we plan on moving this function away from basic-cli in the future, see github.com/roc-lang/basic-cli/issues/73 ## -disable_raw_mode! : {} => {} -disable_raw_mode! = |{}| - Host.tty_mode_canonical!({}) +disable_raw_mode! : () => {} +disable_raw_mode! = || + Host.tty_mode_canonical!() diff --git a/platform/Url.roc b/platform/Url.roc index dfa496d9..15a7720d 100644 --- a/platform/Url.roc +++ b/platform/Url.roc @@ -194,7 +194,7 @@ percent_encode : Str -> Str percent_encode = |input| # Optimistically assume we won't need any percent encoding, and can have # the same capacity as the input string. If we're wrong, it will get doubled. - initial_output = List.with_capacity((Str.count_utf8_bytes(input) |> Num.int_cast)) + initial_output = List.with_capacity(Str.count_utf8_bytes(input) |> Num.int_cast) answer = List.walk( @@ -204,8 +204,8 @@ percent_encode = |input| # Spec for percent-encoding: https://www.ietf.org/rfc/rfc3986.txt if (byte >= 97 && byte <= 122) # lowercase ASCII - || (byte >= 65 && byte <= 90) # uppercase ASCII - || (byte >= 48 && byte <= 57) # digit + or (byte >= 65 && byte <= 90) # uppercase ASCII + or (byte >= 48 && byte <= 57) # digit then # This is the most common case: an unreserved character, # which needs no encoding in a path @@ -228,8 +228,7 @@ percent_encode = |input| List.concat(output, suffix), ) - Str.from_utf8(answer) - |> Result.with_default("") # This should never fail + Str.from_utf8(answer) ?? "" # This should never fail ## Adds a [Str] query parameter to the end of the [Url]. ## @@ -275,7 +274,7 @@ append_param = |@Url(url_str), key, value| without_fragment |> Str.reserve(bytes) - |> Str.concat((if has_query(@Url(without_fragment)) then "&" else "?")) + |> Str.concat(if has_query(@Url(without_fragment)) then "&" else "?") |> Str.concat(encoded_key) |> Str.concat("=") |> Str.concat(encoded_value) @@ -456,7 +455,7 @@ query_params = |url| query(url) |> Str.split_on("&") |> List.walk( - Dict.empty({}), + Dict.empty(), |dict, pair| when Str.split_first(pair, "=") is Ok({ before, after }) -> Dict.insert(dict, before, after) diff --git a/platform/Utc.roc b/platform/Utc.roc index ae7da33f..99cc1962 100644 --- a/platform/Utc.roc +++ b/platform/Utc.roc @@ -17,9 +17,9 @@ import InternalDateTime Utc := I128 implements [Inspect] ## Duration since UNIX EPOCH -now! : {} => Utc -now! = |{}| - @Utc(Num.to_i128(Host.posix_time!({}))) +now! : () => Utc +now! = || + @Utc(Num.to_i128(Host.posix_time!())) # Constant number of nanoseconds in a millisecond nanos_per_milli = 1_000_000 @@ -32,7 +32,7 @@ to_millis_since_epoch = |@Utc(nanos)| ## Convert milliseconds to Utc timestamp from_millis_since_epoch : I128 -> Utc from_millis_since_epoch = |millis| - @Utc((millis * nanos_per_milli)) + @Utc(millis * nanos_per_milli) ## Convert Utc timestamp to nanoseconds to_nanos_since_epoch : Utc -> I128 @@ -46,7 +46,7 @@ from_nanos_since_epoch = @Utc ## Calculate milliseconds between two Utc timestamps delta_as_millis : Utc, Utc -> U128 delta_as_millis = |utc_a, utc_b| - (delta_as_nanos(utc_a, utc_b)) // nanos_per_milli + delta_as_nanos(utc_a, utc_b) // nanos_per_milli ## Calculate nanoseconds between two Utc timestamps delta_as_nanos : Utc, Utc -> U128 diff --git a/platform/main.roc b/platform/main.roc index a014efe3..5fdbca1a 100644 --- a/platform/main.roc +++ b/platform/main.roc @@ -37,7 +37,7 @@ main_for_host! = |raw_args| |> List.map(Arg.from_os_raw) when main!(args) is - Ok({}) -> 0 + Ok() -> 0 Err(Exit(code, msg)) -> if Str.is_empty(msg) then code From 10dd74b597815983eff8ced9b4767c25227c4c17 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Mon, 20 Jan 2025 12:16:51 +1100 Subject: [PATCH 2/2] upgrade to zero arg --- build.roc | 2 +- examples/command.roc | 4 ++-- examples/countdown.roc | 2 +- examples/dir.roc | 4 ++-- examples/echo.roc | 4 ++-- examples/file-mixed.roc | 4 ++-- examples/file-read.roc | 2 +- examples/sqlite.roc | 2 +- examples/task-list.roc | 2 +- examples/tcp-client.roc | 2 +- platform/Cmd.roc | 2 +- platform/Env.roc | 16 ++++++--------- platform/EnvDecoding.roc | 42 ++++++++++++++++++++-------------------- platform/Host.roc | 6 +++--- platform/Locale.roc | 2 +- platform/Sqlite.roc | 2 +- platform/libapp.roc | 2 +- platform/main.roc | 2 +- 18 files changed, 49 insertions(+), 53 deletions(-) diff --git a/build.roc b/build.roc index aea93ba0..87f3ed19 100755 --- a/build.roc +++ b/build.roc @@ -40,7 +40,7 @@ main! = |_args| info!("Successfully built platform files!")? - Ok() + Ok({}) roc_version! : Str => Result {} _ roc_version! = |roc_cmd| diff --git a/examples/command.roc b/examples/command.roc index 6c5676f9..60e7bca0 100644 --- a/examples/command.roc +++ b/examples/command.roc @@ -12,7 +12,7 @@ main! = |_args| exec_example!()? - Ok() + Ok({}) exec_example! : () => Result {} _ exec_example! = || @@ -30,7 +30,7 @@ status_example! = || |> Cmd.status! when result is - Ok(exit_code) if exit_code == 0 -> Ok() + Ok(exit_code) if exit_code == 0 -> Ok({}) Ok(exit_code) -> Stdout.line!("Child exited with non-zero code: ${Num.to_str(exit_code)}") Err(err) -> Stdout.line!("Error executing command: ${Inspect.to_str(err)}") diff --git a/examples/countdown.roc b/examples/countdown.roc index 9ba2b13b..d72d9f1b 100644 --- a/examples/countdown.roc +++ b/examples/countdown.roc @@ -13,7 +13,7 @@ main! = |_args| tick! = |n| if n == 0 then Stdout.line!("๐ŸŽ‰ SURPRISE! Happy Birthday! ๐ŸŽ‚")? - Ok() + Ok({}) else Stdout.line!("${Num.to_str(n)}...")? _ = Stdin.line!() diff --git a/examples/dir.roc b/examples/dir.roc index 3aebe6b3..a75fd026 100644 --- a/examples/dir.roc +++ b/examples/dir.roc @@ -28,7 +28,7 @@ main! = |_args| # Try to create a directory without a parent (should fail, ignore error) when Dir.create!("dirExampleD/child") is - Ok() -> {} + Ok({}) -> {} Err(_) -> {} # Delete an empty directory @@ -39,4 +39,4 @@ main! = |_args| Stdout.line!("Success!")? - Ok() + Ok({}) diff --git a/examples/echo.roc b/examples/echo.roc index 2d50491c..add65d5c 100644 --- a/examples/echo.roc +++ b/examples/echo.roc @@ -18,11 +18,11 @@ tick! = || Err(EndOfFile) -> Stdout.line!(echo("Received end of input (EOF)."))? - Ok() + Ok({}) Err(StdinErr(err)) -> Stdout.line!(echo("Unable to read input ${Inspect.to_str(err)}"))? - Ok() + Ok({}) echo : Str -> Str echo = |shout| diff --git a/examples/file-mixed.roc b/examples/file-mixed.roc index f23c0922..7a4c3f9f 100644 --- a/examples/file-mixed.roc +++ b/examples/file-mixed.roc @@ -31,11 +31,11 @@ task! = || Stdout.line!("I read the file back. Its contents: \"${contents}\"")? - Ok() + Ok({}) main! = |_args| when task!() is - Ok() -> Stdout.line!("Successfully wrote a string to out.txt") + Ok({}) -> Stdout.line!("Successfully wrote a string to out.txt") Err(err) -> msg = when err is diff --git a/examples/file-read.roc b/examples/file-read.roc index ffe1b85a..82379b33 100644 --- a/examples/file-read.roc +++ b/examples/file-read.roc @@ -19,7 +19,7 @@ main! = |_args| Exit(1, "unable to read file: ${msg}") # non-zero exit code to indicate failure - Ok() + Ok({}) run! = || file_name = "LICENSE" diff --git a/examples/sqlite.roc b/examples/sqlite.roc index 5791c9c0..20e613fa 100644 --- a/examples/sqlite.roc +++ b/examples/sqlite.roc @@ -29,7 +29,7 @@ main! = |_args| Stdout.line!("\tid: ${id}, task: ${task}"), )? - Ok() + Ok({}) query_todos_by_status! = |db_path, status| Sqlite.query_many!( diff --git a/examples/task-list.roc b/examples/task-list.roc index 1a4b8bc5..2233dc3a 100644 --- a/examples/task-list.roc +++ b/examples/task-list.roc @@ -11,7 +11,7 @@ main! = |_args| print! : List Str => Result {} _ print! = |authors| when authors is - [] -> Ok() + [] -> Ok({}) [author, .. as rest] -> Stdout.line!(author)? print!(rest) diff --git a/examples/tcp-client.roc b/examples/tcp-client.roc index 293c9cb2..9c46bd50 100644 --- a/examples/tcp-client.roc +++ b/examples/tcp-client.roc @@ -9,7 +9,7 @@ import pf.Stderr main! = |_args| when run!() is - Ok() -> Ok() + Ok({}) -> Ok({}) Err(err) -> handle_err!(err) handle_err! : []_ => Result {} _ diff --git a/platform/Cmd.roc b/platform/Cmd.roc index ab8ed8d2..16b8e8dc 100644 --- a/platform/Cmd.roc +++ b/platform/Cmd.roc @@ -131,6 +131,6 @@ exec! = |program, arguments| |> status!? if exit_code == 0i32 then - Ok() + Ok({}) else Err(CmdStatusErr(Other("Non-zero exit code ${Num.to_str(exit_code)}"))) diff --git a/platform/Env.roc b/platform/Env.roc index c7aa46f9..e1afabc5 100644 --- a/platform/Env.roc +++ b/platform/Env.roc @@ -30,15 +30,14 @@ cwd! = || ## to this directory. set_cwd! : Path => Result {} [InvalidCwd] set_cwd! = |path| - Host.set_cwd!(InternalPath.to_bytes(path)) - |> Result.map_err(|| InvalidCwd) + Host.set_cwd!(InternalPath.to_bytes(path)) |> Result.map_err(|_| InvalidCwd) ## Gets the path to the currently-running executable. exe_path! : () => Result Path [ExePathUnavailable] exe_path! = || when Host.exe_path!() is Ok(bytes) -> Ok(InternalPath.from_os_bytes(bytes)) - Err() -> Err(ExePathUnavailable) + Err({}) -> Err(ExePathUnavailable) ## Reads the given environment variable. ## @@ -46,8 +45,7 @@ exe_path! = || ## [Unicode replacement character](https://unicode.org/glossary/#replacement_character) ('๏ฟฝ'). var! : Str => Result Str [VarNotFound] var! = |name| - Host.env_var!(name) - |> Result.map_err(|| VarNotFound) + Host.env_var!(name) |> Result.map_err(|_| VarNotFound) ## Reads the given environment variable and attempts to decode it. ## @@ -78,7 +76,7 @@ var! = |name| decode! : Str => Result val [VarNotFound, DecodeErr DecodeError] where val implements Decoding decode! = |name| when Host.env_var!(name) is - Err() -> Err(VarNotFound) + Err({}) -> Err(VarNotFound) Ok(var_str) -> Str.to_utf8(var_str) |> Decode.from_bytes(EnvDecoding.format()) @@ -90,8 +88,7 @@ decode! = |name| ## will be used in place of any parts of keys or values that are invalid Unicode. dict! : () => Dict Str Str dict! = || - Host.env_dict!() - |> Dict.from_list + Dict.from_list(Host.env_dict!()) # ## Walks over the process's environment variables as key-value arguments to the walking function. # ## @@ -168,5 +165,4 @@ platform! = || ## temp_dir! : () => Path temp_dir! = || - Host.temp_dir!() - |> InternalPath.from_os_bytes + InternalPath.from_os_bytes(Host.temp_dir!()) diff --git a/platform/EnvDecoding.roc b/platform/EnvDecoding.roc index 153cd59a..b51452c2 100644 --- a/platform/EnvDecoding.roc +++ b/platform/EnvDecoding.roc @@ -26,8 +26,8 @@ EnvFormat := {} implements [ }, ] -format : {} -> EnvFormat -format = || @EnvFormat() +format : () -> EnvFormat +format = || @EnvFormat({}) decode_bytes_to_num = |bytes, transformer| when Str.from_utf8(bytes) is @@ -38,22 +38,22 @@ decode_bytes_to_num = |bytes, transformer| Err(_) -> { result: Err(TooShort), rest: bytes } -env_u8 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u8)) -env_u16 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u16)) -env_u32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u32)) -env_u64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u64)) -env_u128 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_u128)) -env_i8 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i8)) -env_i16 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i16)) -env_i32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i32)) -env_i64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i64)) -env_i128 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_i128)) -env_f32 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_f32)) -env_f64 = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_f64)) -env_dec = Decode.custom(|bytes, @EnvFormat()| decode_bytes_to_num(bytes, Str.to_dec)) +env_u8 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u8)) +env_u16 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u16)) +env_u32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u32)) +env_u64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u64)) +env_u128 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_u128)) +env_i8 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i8)) +env_i16 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i16)) +env_i32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i32)) +env_i64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i64)) +env_i128 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_i128)) +env_f32 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_f32)) +env_f64 = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_f64)) +env_dec = Decode.custom(|bytes, @EnvFormat({})| decode_bytes_to_num(bytes, Str.to_dec)) env_bool = Decode.custom( - |bytes, @EnvFormat()| + |bytes, @EnvFormat({})| when Str.from_utf8(bytes) is Ok("true") -> { result: Ok(Bool.true), rest: [] } Ok("false") -> { result: Ok(Bool.false), rest: [] } @@ -61,7 +61,7 @@ env_bool = Decode.custom( ) env_string = Decode.custom( - |bytes, @EnvFormat()| + |bytes, @EnvFormat({})| when Str.from_utf8(bytes) is Ok(s) -> { result: Ok(s), rest: [] } Err(_) -> { result: Err(TooShort), rest: bytes }, @@ -69,7 +69,7 @@ env_string = Decode.custom( env_list = |decode_elem| Decode.custom( - |bytes, @EnvFormat()| + |bytes, @EnvFormat({})| # Per our supported methods of decoding, this is either a list of strings or # a list of numbers; in either case, the list of bytes must be Utf-8 # decodable. So just parse it as a list of strings and pass each chunk to @@ -84,7 +84,7 @@ env_list = |decode_elem| Err(NotFound) -> { to_parse: all_bytes, remainder: None } - when Decode.decode_with(to_parse, decode_elem, @EnvFormat()) is + when Decode.decode_with(to_parse, decode_elem, @EnvFormat({})) is { result, rest } -> when result is Ok(val) -> @@ -106,7 +106,7 @@ env_list = |decode_elem| env_record : _, (_, _ -> [Keep (Decoder _ _), Skip]), (_, _ -> _) -> Decoder _ _ env_record = |_initialState, _stepField, _finalizer| Decode.custom( - |bytes, @EnvFormat()| + |bytes, @EnvFormat({})| { result: Err(TooShort), rest: bytes }, ) @@ -116,6 +116,6 @@ env_record = |_initialState, _stepField, _finalizer| env_tuple : _, (_, _ -> [Next (Decoder _ _), TooLong]), (_ -> _) -> Decoder _ _ env_tuple = |_initialState, _stepElem, _finalizer| Decode.custom( - |bytes, @EnvFormat()| + |bytes, @EnvFormat({})| { result: Err(TooShort), rest: bytes }, ) diff --git a/platform/Host.roc b/platform/Host.roc index 7384a206..28a37631 100644 --- a/platform/Host.roc +++ b/platform/Host.roc @@ -105,10 +105,10 @@ tcp_write! : TcpStream, List U8 => Result {} Str # SQLITE sqlite_prepare! : Str, Str => Result (Box {}) InternalSqlite.SqliteError sqlite_bind! : Box {}, List InternalSqlite.SqliteBindings => Result {} InternalSqlite.SqliteError -sqlite_columns! : Box () => List Str +sqlite_columns! : Box {} => List Str sqlite_column_value! : Box {}, U64 => Result InternalSqlite.SqliteValue InternalSqlite.SqliteError -sqlite_step! : Box () => Result InternalSqlite.SqliteState InternalSqlite.SqliteError -sqlite_reset! : Box () => Result {} InternalSqlite.SqliteError +sqlite_step! : Box {} => Result InternalSqlite.SqliteState InternalSqlite.SqliteError +sqlite_reset! : Box {} => Result {} InternalSqlite.SqliteError # OTHERS current_arch_os! : () => { arch : Str, os : Str } diff --git a/platform/Locale.roc b/platform/Locale.roc index 2cb1647d..cf667162 100644 --- a/platform/Locale.roc +++ b/platform/Locale.roc @@ -11,7 +11,7 @@ import Host get! : () => Result Str [NotAvailable] get! = || Host.get_locale!() - |> Result.map_err(|| NotAvailable) + |> Result.map_err(|_| NotAvailable) ## Returns the preferred locales for the system or application. ## diff --git a/platform/Sqlite.roc b/platform/Sqlite.roc index aa54b374..c2342dc6 100644 --- a/platform/Sqlite.roc +++ b/platform/Sqlite.roc @@ -239,7 +239,7 @@ execute_prepared! = |{ stmt, bindings }| try(reset!, stmt) when res is Ok(Done) -> - Ok() + Ok({}) Ok(Row) -> Err(UnhandledRows) diff --git a/platform/libapp.roc b/platform/libapp.roc index 41c2a21e..e31f288c 100644 --- a/platform/libapp.roc +++ b/platform/libapp.roc @@ -4,4 +4,4 @@ app [main!] { pf: platform "main.roc" } # executable built correctly just by running it. main! : _ => Result {} [Exit I32 Str]_ main! = |_args| - Err(JustAStub) + Err(Stub) diff --git a/platform/main.roc b/platform/main.roc index 5fdbca1a..a014efe3 100644 --- a/platform/main.roc +++ b/platform/main.roc @@ -37,7 +37,7 @@ main_for_host! = |raw_args| |> List.map(Arg.from_os_raw) when main!(args) is - Ok() -> 0 + Ok({}) -> 0 Err(Exit(code, msg)) -> if Str.is_empty(msg) then code