Stream: beginners

Topic: where are cycles allowed?


view this post on Zulip Brian Hicks (Oct 27 2021 at 23:35):

I’m seeing some compiler hangs and just want to verify some assumptions. Are cycles in module imports allowed? How about cycles in data structure definitions?

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:20):

cycles in imports aren't allowed

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:21):

cycles in type aliases are only allowed within tag unions

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:21):

as far as I know they aren't allowed anywhere else!

view this post on Zulip Brian Hicks (Oct 28 2021 at 00:33):

cool cool cool. Would you expect an import cycle to have given an error right now or is that a TODO? This is in platform code for rbt so maybe it’s being special-cased somehow?

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:36):

yeah we have an explicit error for that one

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:36):

with the fancy box art like Elm does :big_smile:

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:37):

I think we have a general problem in file loading for "file not found" leads to a hang

view this post on Zulip Richard Feldman (Oct 28 2021 at 00:38):

I think the reason for this is that instead of a worker reporting that it finished and failed, it instead doesn't report at all - so other worker(s) wait for it forever

view this post on Zulip Brian Hicks (Oct 28 2021 at 00:54):

cool. I bet I can smoosh all these data types into one module and be fine

view this post on Zulip Brian Hicks (Oct 28 2021 at 00:55):

as far as the other thing, the current design for rbt has Job -> Command -> Tool -> Job. Reckon that can be accommodated or nah? Not familiar enough with the tagged stuff yet to know if it’s reasonable

view this post on Zulip Richard Feldman (Oct 28 2021 at 01:02):

anything you can do with an ADT you can do with a closed tag union, so should be fine!

view this post on Zulip Richard Feldman (Oct 28 2021 at 01:03):

phantom types currently work a little differently, but I assume they won't come up here

view this post on Zulip Brian Hicks (Oct 28 2021 at 01:21):

well, those 3 types are not in the same union. Am I understanding that’s required?

view this post on Zulip Richard Feldman (Oct 28 2021 at 02:23):

nah, so like

view this post on Zulip Richard Feldman (Oct 28 2021 at 02:25):

in Elm you'd write type Result ok err = Ok ok | Err err and in Roc you'd write Result ok err : [ Ok ok, Err err ]

view this post on Zulip Richard Feldman (Oct 28 2021 at 02:26):

in either case you still do Ok 5 and Err "blah" to make one, and you pattern match to destructure them in the same way

view this post on Zulip Richard Feldman (Oct 28 2021 at 02:26):

you can use tags in other ways than this, but this is how to use them to basically be ADTs

view this post on Zulip Richard Feldman (Oct 28 2021 at 02:28):

so an easy way to get started with them is to write what you'd write in Elm, then do the syntactic translation I showed above, and everything will work pretty much the same way you're used to unless you want to make a recursive one or a phantom type! :big_smile:

view this post on Zulip Brian Hicks (Oct 28 2021 at 11:29):

got it. Here's where I've ended up. Do you see anything in this module that would make this error happen? (I figure you might since we were looking at it yesterday) https://github.com/rtfeldman/rbt/pull/15#issuecomment-953756395

view this post on Zulip Richard Feldman (Oct 28 2021 at 11:47):

ahhh I think this might be https://github.com/rtfeldman/roc/issues/1642

view this post on Zulip Richard Feldman (Oct 28 2021 at 11:48):

try defining Tool higher in the file than Command

view this post on Zulip Richard Feldman (Oct 28 2021 at 11:49):

and Command higher than Job

view this post on Zulip Brian Hicks (Oct 28 2021 at 12:21):

ahh, ok. It happens when they’re tag unions too. I guess they use the same mechanism?

view this post on Zulip Richard Feldman (Oct 28 2021 at 12:22):

oh so Foo : ... is Roc's syntax for type aliases - it's equivalent to type alias Foo = ... in Elm

view this post on Zulip Richard Feldman (Oct 28 2021 at 12:22):

so all of those type definitions involving tag unions are type aliases :big_smile:

view this post on Zulip Brian Hicks (Oct 28 2021 at 12:58):

that's what I thought. OK, let's see how far I can get now :smiling_devil:


Last updated: Jul 06 2025 at 12:14 UTC