Stream: beginners

Topic: Export Custom Abilities


view this post on Zulip Ben Plotke (Apr 25 2024 at 18:51):

Is exporting custom abilities intentionally forbidden? I made a red-black tree module, but was not able to import it when it exposed the Sort ability I defined. Using yesterday's build, the compiler panics at crates/compiler/load_internal/src/file.rs:4903:29. I know adding a built in Sort ability is in the roadmap, but has been deferred due to the thorny problem of local aware string sorting. In the mean time, I figured I could define my own.

view this post on Zulip Luke Boswell (Apr 25 2024 at 20:46):

Have you seen https://www.roc-lang.org/abilities

view this post on Zulip Luke Boswell (Apr 25 2024 at 20:47):

Would you be able to share your code? The compiler definitely shouldn't panic, and give a nice warning instead.

view this post on Zulip Ben Plotke (Apr 25 2024 at 22:36):

Uh, it's half baked, but here goes https://gist.github.com/benplotke/72f8162f6b4e43b3ed3eb712c5030ac3
The file which fails to import it is in the same directory and contains. If I remove Sort from the exports, the below compiles w/o complaint.

interface OrderedSet
    exposes [
    ]
    imports [
        RedBlackTree
    ]

view this post on Zulip Ben Plotke (Apr 25 2024 at 22:51):

Luke Boswell said:

Have you seen https://www.roc-lang.org/abilities

Yeah!. At the risk of side tracking this thread, I read the thread related to adding Sort. I would think it would be ok to make Sort and not define it for string. While I have no idea how to solve the problem properly for strings, I was thinking in the meantime I could wrap my strings in an Opaque that fits the context of the strings, and then use a fitting sort, e.g. lexicographic or semver.

view this post on Zulip Ben Plotke (Apr 26 2024 at 12:03):

I just confirmed, it will repro if the ability is the only thing in the exporting file.
I made SortAbility.Roc

interface SortAbility
    exposes [
        Sort,
    ]
    imports []

Sort implements
    compare : a, a -> [LessThan, Equal, GreaterThan] where a implements Sort

and OrderedSet.roc

interface OrderedSet
    exposes [
    ]
    imports [
        SortAbility
    ]

running roc test OrderedSet.roc panics with

thread '<unnamed>' panicked at crates/compiler/load_internal/src/file.rs:4903:29:
Import ability member `18.IdentId(1)` not available

view this post on Zulip Luke Boswell (Apr 26 2024 at 12:14):

Interesting, it may be resolved by the new module changes PR Agus is working on. It looks like it thinks there is a missing identifier somehow.

view this post on Zulip Ben Plotke (Apr 26 2024 at 12:41):

This comment made me think I might be able to define the ability in both places, but on trying, I found the two definitions are considered distinct, which is what I would expect.

// Today we define builtins in each module that uses them
 // so even though they have a different module name from
 // the surrounding module, they are not technically imported

view this post on Zulip Ben Plotke (Apr 26 2024 at 12:42):

Luke Boswell said:

Interesting, it may be resolved by the new module changes PR Agus is working on. It looks like it thinks there is a missing identifier somehow.

Interesting. I'll try again after the PR goes through. If it still panics, I'll file a bug

view this post on Zulip Ben Plotke (May 02 2024 at 12:07):

Still repros with Agus's PR merged. I filed a bug https://github.com/roc-lang/roc/issues/6702


Last updated: Jul 06 2025 at 12:14 UTC