I'm working through AoC and I want to split off my parsing code from my main.roc file, so that I can separate my puzzle logic from my input logic. I tried making different combinations of package and interface modules, but regardless I keep getting compile errors (mostly around my "imports" lines, for whatever reason).
-> what's a minimal example of a Roc app module that pulls code from other local modules?
file structure:
├── deps
│ ├── ParsedText.roc
│ └── main.roc
├── input.txt
└── main.roc
main.roc
:
app "day2"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
deps: "deps/main.roc",
}
imports [
pf.Stdout,
deps.ParsedText.{ text },
]
provides [main] to pf
main =
Stdout.line text
deps/main.roc
:
package "deps"
exposes [ParsedText]
packages {
# I also want this code to depend on an external package, w/o having to pollute my app code's dependencies
parse: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.3.0/-e3ebWWmlFPfe9fYrr2z1urfslzygbtQQsl69iH1qzQ.tar.br",
}
ParsedText.roc
:
interface ParsedText
exposes [text]
imports [
parse.parseStr,
parse.string,
]
text = parseStr (string "text") "text" == Ok "text"
compile error for roc build
:
── WEIRD IMPORTS ───────────────────────────────────────── deps/ParsedText.roc ─
I am partway through parsing a imports list, but I got stuck here:
2│ exposes [text]
3│ imports [
4│ parse.parseStr,
^
I am expecting a comma or end of list, like
imports [Shape, Vector]%
... do I not have a comma? I'm not sure what to do here.
Do you want to make a package or just separate into another module? If you move the ParsedText.roc to the same folder as your main.roc you can just directly import it, i.e. remoce the deps. prefix.
It looks like you wamt to use a package to keep the parser dep separate. I'm not sure about how to do that, I tried a bit with my aoc-template and ended up just vendoring the Parser package code.
https://github.com/lukewilliamboswell/aoc/blob/main/src/S2023/D02.roc
If you look at my day 2 you can see how I have achieved that, but it feels like a workaround.
Yeah a "package" module is supposed to be something loaded from far away, like the package manager that doesn't exist yet!
Within your own app you only need interface
modules.
so remove the "package" bit and just use interfaces, got it!
yeah I don't mind too much if my top-level app module has to list roc-parser as a dependency, I can live with that. as long as I can access it from my interface that's fine for now.
lemme give it a go and see what happens... :fingers_crossed:
Yeah that works. If your app imports the package. The interface modules can import it to woth the same prefix I think
yeah I'm still getting errors T-T
code is in this GH-Gist (I forgot about gists, this is way cleaner :sweat_smile:)
https://gist.github.com/CrepeGoat/222803ee7bc1ff665fe679d8e96c9018
error:
── WEIRD IMPORTS ────────────────────────────────────────────── ParsedText.roc ─
I am partway through parsing a imports list, but I got stuck here:
2│ exposes [text]
3│ imports [
4│ parse.parseStr,
^
I am expecting a comma or end of list, like
imports [Shape, Vector]%
Do we have different parsing for imports in interfaces? That would be surprising.
I think you still need the module name so parse.Core
Or parse.Core.{ parseStr, ...etc}
Also unrelated but you wont be able to print text directly to Stdout as it's a Bool. Maybe just use dbg and roc dev, and print an empty string or something.
Luke Boswell said:
Also unrelated but you wont be able to print text directly to Stdout as it's a Bool. Maybe just use dbg and roc dev, and print an empty string or something.
yeah I'm seeing that now too, thanks!
Luke Boswell said:
I think you still need the module name so
parse.Core
that made the file parse-able! thanks
though the error message I got for that was really unhelpful. tbh I still don't know why specifying a wrong path for a dependency (i.e., a semantic issue) prevented the entire file from being parsed or formatted (i.e., behaved like a syntax issue). is this worth filing a bug over?
That sounds like progress :fingers_crossed:
I think it would be helpful to document it. We can add context Re module params development which will replace a lot of the underlying implementation, and almost certainly resolve this issue.
Also good to link to when someone else runs into this issue. I did yesterday, but just pressed on instead of stopping to question if I should.
haha yeah AoC this year is a lot more bug-filing and typo-fixing than I remember in past years :joy: I'll write something up and post the link here. thanks again!
OOOHH weird! so if I take my old broken example and capitalize my imports, it then parses and gives me a semantic error.
e.g. can't parse and errors with ~"bad import syntax. add a comma?":
interface ParsedText
exposes [text]
imports [
parse.parseStr,
parse.string,
]
can parse but errors with ~"can't find that module":
interface ParsedText
exposes [text]
imports [
parse.ParseStr,
parse.String,
]
That makes sense and is probably super useful for a repro in an issue.
It expects package.Module
. So the first is lowecase and the second capitilized.
issue posted here: https://github.com/roc-lang/roc/issues/6172
thanks all!
Becker A. has marked this topic as resolved.
@Richard Feldman @Agus Zubiaga related question, should it be possible to import a package into another package? is this currently implemented?
I’m afk but I think you can just use the packages
keyword in the package
header like you do for apps. I don’t remember if I have done this before, though.
Looks like I have according to this issue’s description: https://github.com/roc-lang/roc/issues/5477
You will probably run into that but you can workaround it by importing the transitively used modules in the app
This is one of the main issues I want to fix as part of module params
yeah tl;dr it should be possible but there's a bug currently :big_smile:
Sounds good. This will mean we can use roc-lang/unicode things in roc-parser. :grinning_face_with_smiling_eyes:
See also #beginners > How to import interface from another directory?
Last updated: Jul 06 2025 at 12:14 UTC