Given that we say the wildcard type is compatible with any type, it's kind of strange you get a TYPE MISMATCH
error in a case like this:
── TYPE MISMATCH ───────────────────────────────────── examples/helloWorld.roc ─
Something is off with the body of the lst definition:
7│ lst : List *
8│ lst = [1]
^^^
The body is a list of type:
List Num *
But the type annotation on lst says it should be:
List *
Tip: The type annotation uses the type variable * to say that this
definition can produce any type of value. But in the body I see that
it will only produce a Num value of a single specific type. Maybe
change the type annotation to be more specific? Maybe change the code
to be more general?
Should we make the error something like "type must be specific"?
no, we always believe the type signature over the actual body
yeah I think the error message has all the correct information. Maybe the wording could be better? :thinking:
no, we always believe the type signature over the actual body
Oh yeah, that's no problem. I meant that it's a bit strange that we call it a mismatch. If we say *
is compatible with any type, we should not say the types don't match. Because the actual problem is that the type is not specific enough. It seems reasonable to make a separate error category for the "not specific enough" case. It's very different to e.g. a mismatch where you are using aStr
type instead of U64
.
but the problem here is that the implementation is too specific? it picks a narrower type than the signature says it is
but the problem here is that the implementation is too specific
Yeah, you can say "the provided implementation is too specific" or "the provided type signature is not specific enough"
maybe something like this?
── BODY DOES NOT MATCH ANNOTATION ─────────────────── examples/helloWorld.roc ─
The body of the lst definition does not match its type annotation:
7│ lst : List *
8│ lst = [1]
^^^
The body is a list of type:
List (Num *)
This is a narrower type than what the annotation on lst says it should be:
List *
Tip: The type annotation uses the type variable * to say that this
definition can produce any type of value. But in the body I see that
it will only produce a Num value of a single specific type. Maybe
change the type annotation to be more specific? Maybe change the code
to be more general?
Looks good, I would add some color or other emphasis to "narrower type" and "Maybe change the type annotation to be more specific? Maybe change the code to be more general?"
Perhaps also use "more specific" instead of "narrower" for international English speakers.
This feels like a case where giving a counter example would be useful. Though not sure if that can be easily added to the error message rather than as a page on the website with multiple examples
I think it's a good idea in general to add a link to the website to error messages for an in depth explanation where useful.
Last updated: Jul 06 2025 at 12:14 UTC