Stream: beginners

Topic: Encoding Ability


view this post on Zulip Luke Boswell (Mar 15 2023 at 04:01):

Just trying to wrap my head around Abilities and the Json implementation at a deeper level, and I'm unsure about something.

What do we need the Encoding ability in crates/compiler/builtins/roc/Encode.roc for?

Encoding has
    toEncoder : val -> Encoder fmt | val has Encoding, fmt has EncoderFormatting

I can delete Encoding and all my Json tests still pass which seems strange.

view this post on Zulip Brendan Hansknecht (Mar 15 2023 at 05:09):

Encoding should be going from a Roc type to a Json byte List.

view this post on Zulip Brendan Hansknecht (Mar 15 2023 at 05:09):

Do you have tests for that?

view this post on Zulip Luke Boswell (Mar 15 2023 at 05:28):

Actually.. it is needed. I can't build roc without it. Disregard my question above. @Brendan Hansknecht yeah I'm trying to add more tests, and fix bugs along the way.

view this post on Zulip Luke Boswell (Mar 15 2023 at 05:50):

I've got a strange bug I'm trying to track down. When I add the following test to the Json.roc file it fails with Err (Leftover [123, ... all the other bytes]). But when I add to another random file it passes.

It's strange because it doesn't even parse a single byte.

expect
    input = Str.toUtf8 "{\"name\":\"Röc Lang\"}"
    actual = Decode.fromBytes input fromUtf8
    expected = Ok { name: "Röc Lang" }

    actual == expected

view this post on Zulip Brian Carroll (Mar 15 2023 at 06:06):

Sure sounds like a compiler bug! Probably worth creating an issue. @Ayaz Hafiz is this something you know about?

view this post on Zulip Ayaz Hafiz (Mar 15 2023 at 18:19):

seems like a bug in the JSON implementation, but not with abilities themselves. The JSON impl definitely could use some love


Last updated: Jul 05 2025 at 12:14 UTC