Stream: beginners

Topic: Eq ability for Dict


view this post on Zulip Ilya Shmygol (Apr 22 2025 at 17:46):

Don't Dicts implement Eq-ability? Is there a ticket for it?

view this post on Zulip Anton (Apr 22 2025 at 17:52):

This works:

Stdout.line!(Inspect.to_str((Dict.single("A", "B") == Dict.single("A", "B"))))

Can you provide your code?

view this post on Zulip Ilya Shmygol (Apr 22 2025 at 18:14):

Oh, it was F64, which doesn't implement Eq. My bad. The error message was confusing presumingly because of other errors. After I fixed other errors I see a better error message even with a great hint about the reasoning around float not implementing Eq:

── TYPE MISMATCH in ./RestApi.roc ──────────────────────────────────────────────

This expression has a type that does not implement the abilities it's expected to:

36│      actual == Ok(database)
         ^^^^^^

I can't generate an implementation of the Eq ability for

    [
        Err *,
        Ok Database,
    ]

In particular, an implementation for

    FloatingPoint ?

cannot be generated.

Note: I can't derive Bool.is_eq for floating-point types. That's
because Roc's floating-point numbers cannot be compared for total
equality - in Roc, `NaN` is never comparable to `NaN`. If a type
doesn't support total equality, it cannot support the Eq ability!

The previous error was:

── TYPE MISMATCH in ./RestApi.roc ──────────────────────────────────────────────

This expression has a type that does not implement the abilities it's expected to:

36│      actual == Ok(database)
         ^^^^^^

I can't generate an implementation of the Eq ability for

    [
        Err *,
        Ok Database,
    ]

In particular, an implementation for

    ?

cannot be generated.

I appritiate the note, but this question mark even here FloatingPoint ? is not easy to read. Why doesn't the compiler write the type variable instead of the question mark?

view this post on Zulip Anton (Apr 23 2025 at 08:11):

I'm not sure, can you share the related block of code?

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:46):

The compiler uses question mark to point out what is unknown in a type.

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:46):

If no date is known, just a question mark

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:47):

If some data is know like they type being a floating point, it adds that info

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:48):

I think it is mostly done for clarity of new learners

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:48):

But I don't actually know the original incentives, so that is just a guess.

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:48):

I'm a bit surprised it is FloatingPoint ? and not F64

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 15:50):

I feel like if I saw FloatingPoint a or FloatingPoint unknown, it wouldn't really be clearer than `FloatingPoint ?. But I guess it would be more familiar as it is still a type variable.

view this post on Zulip Ilya Shmygol (Apr 23 2025 at 16:14):

The thing is the full type should have been known in my opinion. It was just F64. I'll try to find time today and post the code. I've fixed the error, so would need time to reproduce it.

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 22:27):

:nod-yes: yeah, I would guess it is a big in the output

view this post on Zulip Ilya Shmygol (Apr 24 2025 at 10:52):

Even is a simple example like this the compiler doesn't seem to recognise the type and references the type variable as ?:

expect
    a : List F64
    a = [1.0]
    b : List F64
    b = [1.0]

    a == b

Error:

── TYPE MISMATCH in ./Delme.roc ────────────────────────────────────────────────

This expression has a type that does not implement the abilities it's expected to:

11│      a == b
         ^

I can't generate an implementation of the Eq ability for

    List (Frac ?)

In particular, an implementation for

    FloatingPoint ?

cannot be generated.

Note: I can't derive Bool.is_eq for floating-point types. That's
because Roc's floating-point numbers cannot be compared for total
equality - in Roc, `NaN` is never comparable to `NaN`. If a type
doesn't support total equality, it cannot support the Eq ability!

Why not F64 or at least something like?

FloatingPoint Signed64
              ^^^^^^^^

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 15:45):

I wonder if this was intentional but led to a bad error message accidentally. Like the computer is trying to say it can't generate Eq for any floating point types and just printing that poorly.

view this post on Zulip Ilya Shmygol (Apr 24 2025 at 15:53):

Brendan Hansknecht said:

I wonder if this was intentional but led to a bad error message accidentally. Like the computer is trying to say it can't generate Eq for any floating point types and just printing that poorly.

I doubt so. My initial error, which I struggle to reproduce now was just stating ? without any hints, i.e.:

── TYPE MISMATCH in ./RestApi.roc ──────────────────────────────────────────────

This expression has a type that does not implement the abilities it's expected to:

36│      actual == Ok(database)
         ^^^^^^

I can't generate an implementation of the Eq ability for

    [
        Err *,
        Ok Database,
    ]

In particular, an implementation for

    ?

cannot be generated.

Last updated: Jul 06 2025 at 12:14 UTC