Stream: beginners

Topic: ✔ roc dev "did you have a type mismatch" panic


view this post on Zulip Michał Łępicki (Oct 17 2022 at 15:46):

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?

view this post on Zulip Michał Łępicki (Oct 17 2022 at 15:49):

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

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 15:50):

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?

view this post on Zulip Michał Łępicki (Oct 17 2022 at 15:50):

I'll try to remove as much code as possible :thumbs_up:

view this post on Zulip Michał Łępicki (Oct 17 2022 at 16:26):

Opened #4348

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 16:26):

Thank you!

view this post on Zulip Michał Łępicki (Oct 17 2022 at 16:27):

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

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 16:27):

Yes please

view this post on Zulip Michał Łępicki (Oct 17 2022 at 16:31):

opened #4349

view this post on Zulip Notification Bot (Oct 17 2022 at 16:31):

Michał Łępicki has marked this topic as resolved.

view this post on Zulip Ayaz Hafiz (Oct 17 2022 at 16:40):

Why should it not compile? It looks correct type-wise

view this post on Zulip Michał Łępicki (Oct 17 2022 at 16:40):

sorry, just re-read it and yes, it's correct (removed comment)


Last updated: Jul 06 2025 at 12:14 UTC