Stream: beginners

Topic: ✔ Trouble importing another Roc file


view this post on Zulip Ian McLerran (Jan 11 2024 at 14:03):

Suppose I have two Roc files - one defines an interface, and another an app. I want to import my interface into my app.
The interface (BinaryTree.roc) looks like:

interface BinaryTree
    exposes [
        Tree, Node, Null, listToTree, hasLhs, hasRhs,
    ]
# rest of roc code ...

And the complete app (LeafSimilar.roc) code is:

app "leafsimilar"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.1/..." }
    imports [
        pf.Stdout,
        BinaryTree.{
            Tree,
            Node,
            Null,
            listToTree,
            hasLhs,
            hasRhs
        }
    ]
    provides [main] to pf

main = Stdout.line "Hello, world!"

But when I run roc dev LeafSimilar.roc, I get an error message that doesn't make much sense to me:

── WEIRD IMPORTS ────────────────────────────────────────────── BinaryTree.roc ─

I am partway through parsing a header, but I got stuck here:

10│      ]
          ^

I am expecting the imports keyword next, like

    imports [Animal, default, tame]

I'm not finding much documentation on how to do imports, but from the examples I've looked at, I think my import statement looks good, also the error message doesn't really make sense, as I see no reason that it would expect the imports statement next, on line 10, after my existing imports statement. Any help?

view this post on Zulip Brian Carroll (Jan 11 2024 at 14:18):

At the top right of the error message it shows the filename BinaryTree.roc. Can you also show us the full header of that file?

view this post on Zulip Brian Carroll (Jan 11 2024 at 14:20):

Without seeing it, my guess is that you might need to add an empty imports?

view this post on Zulip Ian McLerran (Jan 11 2024 at 14:24):

That was it - thanks!

view this post on Zulip Notification Bot (Jan 11 2024 at 14:25):

Ian McLerran has marked this topic as resolved.

view this post on Zulip Brian Carroll (Jan 11 2024 at 18:59):

Maybe the filename is too easy to miss in our error message layout?


Last updated: Jul 06 2025 at 12:14 UTC