Stream: beginners

Topic: Importing from a url into an interface module


view this post on Zulip Isaac Van Doren (Oct 08 2023 at 21:33):

I’d like make a Parser interface module which exports a function and some types to be used in my main app module. To implement the Parser module I’d like to use the roc-parser package imported from a url but I can’t figure out how to get it imported into the interface module. How can I do this?

view this post on Zulip Luke Boswell (Oct 08 2023 at 23:08):

I don't think it is possible right now, though I'mnot 100%. @Richard Feldman has a mature proposal to change the way modules work which I think enables this. My understanding is that you will be able to import packages at the root of your app and then pass them into your modules.

view this post on Zulip Luke Boswell (Oct 08 2023 at 23:09):

https://docs.google.com/document/u/0/d/110MwQi7Dpo1Y69ECFXyyvDWzF4OYv1BLojIm08qDTvg/mobilebasic

view this post on Zulip Luke Boswell (Oct 08 2023 at 23:09):

Sorry for fornatting the link, but ^^ is the module vhanges proposal.

view this post on Zulip Luke Boswell (Oct 08 2023 at 23:10):

And this is one of the zulip discussions https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/module.20and.20package.20changes/near/372121793

view this post on Zulip Richard Feldman (Oct 08 2023 at 23:57):

I think this is referring to something else - are you just looking to get around the namespace collision @Isaac Van Doren?

view this post on Zulip Richard Feldman (Oct 08 2023 at 23:58):

like you can import parser.Parser but then there's a conflict because you're importing a module named Parser into a module named Parser?

view this post on Zulip Isaac Van Doren (Oct 09 2023 at 01:18):

There's no namespace collision here because the parser package exposes modules named Core and String. I was just hoping to be able to import the modules via url and then access them from a different module in my project than the app module. If that's not possible I can just either copy the parser source files or put everything in the app module.

view this post on Zulip Brendan Hansknecht (Oct 09 2023 at 01:19):

Do we currently url import in the main app and then that makes it available to submodlues if they want it?

view this post on Zulip Brendan Hansknecht (Oct 09 2023 at 01:19):

not sure, just a thought of what might be implemented

view this post on Zulip Agus Zubiaga (Oct 09 2023 at 01:19):

Yeah, that should work, you just need to use the same alias you gave it in the app module you're importing the interface from.

view this post on Zulip Agus Zubiaga (Oct 09 2023 at 01:22):

You might hit some weirdness, but it should work in most simple cases

view this post on Zulip Isaac Van Doren (Oct 09 2023 at 01:27):

Hm okay. So here in the same directory I have
main.roc

app "main"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br",
        parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.1.0/vPU-UZbWGIXsAfcJvAnmU3t3SWlHoG_GauZpqzJiBKA.tar.br",
    }
    imports [
        pf.Stdout,
        pf.Task.{ Task },
        Parser,
    ]
    provides [main] to pf

main : Task {} I32
main =
    foo = Parser.parse
    Stdout.line "the end"

and Parser.roc

interface Parser
    exposes [parse]
    imports [parser.Core]

parse = Core.const "foo"

And when I run it I get

── MODULE NOT IMPORTED ──────────────────────────────────────────── Parser.roc ─

The `Core` module is not imported:

5  parse = Core.const "foo"
            ^^^^^^^^^^

Did you mean to import it?

Can you tell what I'm missing @Agus Zubiaga ?

view this post on Zulip Agus Zubiaga (Oct 09 2023 at 01:29):

Oh, that's weird. I wonder if that's a case of the issue I shared. Try importing parser.Core in main.roc even though you don't use it directly there.

view this post on Zulip Isaac Van Doren (Oct 09 2023 at 01:30):

Ah yeah that worked! Thanks!


Last updated: Jul 06 2025 at 12:14 UTC