Stream: beginners

Topic: Confusing type error


view this post on Zulip Nick Hallstrom (Mar 14 2023 at 18:42):

I just got this type check error. Unless I'm missing something, those two lines are the exact same:

── TYPE MISMATCH ────────────────────────────────────────────────── Parser.roc ─

Something is off with the body of the makeParser definition:

15│   makeParser : Foo * -> (List [Gt]*, Nat -> [Parsed [Gt], ParseFailed, DeadEnd])
16│   makeParser = \f ->
17│>      \items, index ->
18│>          when List.get items index is
19│>              Ok item -> f item
20│>              Err OutOfBounds -> DeadEnd

The body is an anonymous function of type:

    List [Gt]*, Nat -> [DeadEnd, ParseFailed, Parsed [Gt]]

But the type annotation on makeParser says it should be:

    List [Gt]*, Nat -> [DeadEnd, ParseFailed, Parsed [Gt]]

Foo is:

Foo a : [Gt]a -> [Parsed [Gt], ParseFailed, DeadEnd]

view this post on Zulip Folkert de Vries (Mar 14 2023 at 18:45):

yeah, this can happen when the type checker gets confused. This is a bug

view this post on Zulip Folkert de Vries (Mar 14 2023 at 18:45):

there are some secret variables that we don't show to users, but they make the two types different

view this post on Zulip Nick Hallstrom (Mar 14 2023 at 18:49):

Gotcha. Ya just removing the type annotation seems to have fixed it, just wanted to make sure it was a known issue :thumbs_up:

view this post on Zulip Richard Feldman (Mar 14 2023 at 18:51):

can you make a permalink to a commit that reproduces it real quick?

view this post on Zulip Richard Feldman (Mar 14 2023 at 18:51):

would be helpful for fixing it later!

view this post on Zulip Nick Hallstrom (Mar 14 2023 at 19:09):

Sure! Here you go!
https://github.com/Billzabob/roc-lox/tree/6b7487a75cdaca08f9c8e5aa4c7500e0deb04b95

view this post on Zulip Richard Feldman (Mar 14 2023 at 19:17):

awesome, thank you!


Last updated: Jul 05 2025 at 12:14 UTC