Stream: beginners

Topic: Encoding tags


view this post on Zulip Jasper Woudenberg (Jul 16 2026 at 19:40):

Playing with the encoders, I noticed that currently tags without parameters are encoded as strings, and tags with parameters are single-keyed records with the value a tuple of the tag's parameters.

Is this intended as a temporary design to unlock JSON encoding/decoding, or the final design? Asking because I'd love to be able to write an encoder that encodes tags differently!

view this post on Zulip Anton (Jul 17 2026 at 15:32):

@Richard Feldman

view this post on Zulip Richard Feldman (Jul 17 2026 at 15:44):

@Jasper Woudenberg I mostly picked that to unblock json, but it's definitely not set in stone? What did you have in mind for your use case?

view this post on Zulip Jasper Woudenberg (Jul 17 2026 at 15:55):

With the encoding format Rvn I'm working on the idea is that Roc datastructures are encoded pretty much the same way they look like in Roc, tags included. So I'd love to be able to distinguish tags and strings when encoding.

A low-effort idea: encode_tag : state -> Result(state, err), that Roc-derived encoders call just before continuing encoding the tag in exactly the same way it does today. An encoder that wants to could set a flag on state to indicate that the next call to encode_record will be for a tag. And libraries that don't want to do anything special with tags can just pass state through without doing anything extra.

Alternatively encode_tag could function as the full-fledged equivalent of encode_record, but for tags. Downside: every encoder would need to implement it.


Last updated: Jul 23 2026 at 13:15 UTC