code :
app "hello"
packages { pf: "/home/arti/roc/examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Program]
provides [main] to pf
main =
num = addAndStringify 4 5
Stdout.line "hiden number \(num)" |> Program.quick
addAndStringify = \num1, num2 ->
sum = num1 + num2
if sum == 0 then
""
else
Num.toStr (num1 + num2)
error:
roc dev
── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc ─
This 2nd argument to isEq has an unexpected type:
14│ if sum == 0 then
^
The argument is a number of type:
Num *
But isEq needs its 2nd argument to be:
Num a | a has Eq
── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc ─
This 1st argument to addAndStringify has an unexpected type:
9│ num = addAndStringify 4 5
^
The argument is a number of type:
Num *
But addAndStringify needs its 1st argument to be:
Num * | * has Eq
── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc ─
This 2nd argument to addAndStringify has an unexpected type:
9│ num = addAndStringify 4 5
^
The argument is a number of type:
Num *
But addAndStringify needs its 2nd argument to be:
Num * | * has Eq
────────────────────────────────────────────────────────────────────────────────
3 errors and 0 warnings found in 39 ms.
You can run the program anyway with roc run
a bit unexpected : )
@Ayaz Hafiz how can we do a better job here?
Num *
should always be Eq
is there version which have it done right ?
I mean nightly build ?
I think this is https://github.com/roc-lang/roc/issues/4594 probably?
yes looks like it
for now you just need to tell the compiler what types your numbers have
so num = addAndStringify 4i64 5
would probably do it
I tried u8 before and it doesn't worked but I will try again
maybe you need a type signature on the function then
main =
num = addAndStringify 4i8 5i8
Stdout.line "hiden number \(num)" |> Program.quick
addAndStringify = \num1, num2 ->
sum = num1 + num2
if sum == 0i8 then
""
else
Num.toStr (num1 + num2)
works
maybe I messed up before
Last updated: Jul 06 2025 at 12:14 UTC