Stream: platform development

Topic: tagged union example?


view this post on Zulip Brian Hicks (Oct 30 2021 at 11:24):

hey, just trying to read some tagged unions (these: https://github.com/rtfeldman/rbt/blob/f6fb63e103147e795d7187b8d1a76842354f3c35/Rbt.roc) out of Roc using Rust and having some difficulties, specifically getting some segfaults. Y'all got any tips on how to read the memory for tags? Here's what I'm working with now: https://github.com/rtfeldman/rbt/blob/2c9337212cc59a05814f88e5adfa869ba86c2cf9/src/lib.rs

Also, there has to be a better way to debug this than to try things blindly—what is it? I know I could make a lot more progress if I knew how to enter a debugger or at least dump the memory to stdout somehow. Surely options exist and I'm just unaware of them. Someone enlighten me so I can get off your lawn. :laughing:

view this post on Zulip Folkert de Vries (Oct 30 2021 at 11:29):

getting tagged unions out of roc into rust or anything will be tricky. There are a lot of ways that we can represent those compactly (e.g. just a number if none of the tags have payloads as a simple example)

view this post on Zulip Folkert de Vries (Oct 30 2021 at 11:30):

looks like you actually just want to pass records though?

view this post on Zulip Folkert de Vries (Oct 30 2021 at 11:32):

then what's important is that roc sorts fields first by alignment, and then alphabetically. That has to be mirrored on the rust side to have things line up

view this post on Zulip Brian Hicks (Oct 30 2021 at 12:48):

thing is, eventually Tool will need to depend on Job, creating a loop. If I understand that correctly, it means that all the records will need to exist in a single union. Is that right? So even though I’m currently just making private records, I think it will have to change

view this post on Zulip Brian Hicks (Nov 05 2021 at 15:06):

so I think I'd need to do this:

RbtObj : [ InternalJob { command : RbtObj, ... }, InternalCommand { tool : RbtObj }, InternalTool { ..., from : RbtObj } ]

Job : [ @Job RbtObj ]
Command : [ @Command RbtObj ]
Tool : [ @Tool RbtObj ]

Does that seem right? I don't like that it loses type safety, but I don't know that there's a cleaner way to resolve the cycle between the type aliases that it creates. Then I'm gonna have to unwrap two levels of tags here.

view this post on Zulip Brian Hicks (Nov 07 2021 at 14:01):

@Folkert de Vries any advice here?

view this post on Zulip Folkert de Vries (Nov 07 2021 at 14:03):

I don't think this is needed. What sort of functions would you want to write for the host <-> roc communication?

view this post on Zulip Folkert de Vries (Nov 07 2021 at 14:03):

or rather, what are their signatures

view this post on Zulip Brian Hicks (Nov 07 2021 at 15:42):

In this host, the Roc code just provides data for the platform to use. It’s for build specification.

view this post on Zulip Brian Hicks (Nov 07 2021 at 15:42):

I wasn’t planning on exposing any functions at all

view this post on Zulip Brian Hicks (Nov 07 2021 at 15:44):

There will be a separate discovery platform that will though


Last updated: Jul 05 2025 at 12:14 UTC