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?
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.
https://docs.google.com/document/u/0/d/110MwQi7Dpo1Y69ECFXyyvDWzF4OYv1BLojIm08qDTvg/mobilebasic
Sorry for fornatting the link, but ^^ is the module vhanges proposal.
And this is one of the zulip discussions https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/module.20and.20package.20changes/near/372121793
I think this is referring to something else - are you just looking to get around the namespace collision @Isaac Van Doren?
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
?
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.
Do we currently url import in the main app and then that makes it available to submodlues if they want it?
not sure, just a thought of what might be implemented
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.
You might hit some weirdness, but it should work in most simple cases
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 ?
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.
Ah yeah that worked! Thanks!
Last updated: Jul 06 2025 at 12:14 UTC