main = Program.quick mainTask
mainTask =
fileContents <- Task.await (File.readUtf8 (Path.fromStr "../2"))
commands =
fileContents
|> Str.trim
|> Str.split "\n"
|> List.keepOks parseCommand
{ horizontal, depth } =
List.walk commands { horizontal: 0, depth: 0 } navigate
Stdout.line (Num.toStr (horizontal * depth))
parseCommand = \line ->
{ before: direction, after: amountStr } <- Result.try (Str.splitFirst line " ")
amount <- Result.try (Str.toI32 amountStr)
when direction is
"forward" -> Ok (Forward amount)
"down" -> Ok (Down amount)
"up" -> Ok (Up amount)
_ -> Err BadDirection
navigate = \{ horizontal, depth }, command ->
when command is
Forward x -> { horizontal: horizontal + x, depth: depth }
Down x -> { horizontal: horizontal, depth: depth + x }
Up x -> { horizontal: horizontal, depth: depth - x }
I am getting this when running:
$ roc dev 2/2a.roc
🔨 Rebuilding platform...
thread 'main' panicked at 'Equality of different layouts; did you have a type mismatch?
Builtin(Str) == LambdaSet(LambdaSet { set: [( 16.15, [Builtin(Str)])], representation: Interned(7, PhantomData) })', crates/compiler/gen_llvm/src/llvm/compare.rs:151:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
This doesn't look right, should I open an issue?
This works fine if I move the when direction
to a separate function like this:
parseCommand = \line ->
{ before: direction, after: amountStr } <- Result.try (Str.splitFirst line " ")
amount <- Result.try (Str.toI32 amountStr)
parseDirection direction amount
parseDirection = \direction, amount ->
when direction is
"forward" -> Ok (Forward amount)
"down" -> Ok (Down amount)
"up" -> Ok (Up amount)
_ -> Err BadDirection
Yes, could you please file an issue? I think I see the problem here so it should be a straightforward fix, but if possible, could you please cut down a minimal reproduction?
I'll try to remove as much code as possible :thumbs_up:
Opened #4348
Thank you!
Got a different one when reducing:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x01\x00\x00\x00\x10\x00\x00\x00\xb0*`#\x94\x17\xef\xa8"), definition of value binding ValueId(3): expected type '(union { ((),), ((),) }, ())', found type '((), ())'', crates/compiler/gen_llvm/src/llvm/build.rs:4504:23
should I open an issue for this as well? It's
main = Program.quick (Task.succeed f)
f =
ir = Ok 1
i <- Result.try ir
when ir is
Ok 2 -> Ok i
_ -> Err Bad
Yes please
opened #4349
Michał Łępicki has marked this topic as resolved.
Why should it not compile? It looks correct type-wise
sorry, just re-read it and yes, it's correct (removed comment)
Last updated: Jul 06 2025 at 12:14 UTC