The examples of interface packages I was able to find place the interface file for interface Foo
in Foo.roc
, and then add Foo
to imports
. How does one do that when you want to move Foo.roc
to another directory?
Haven't tested, but I thought you just used an extra name capitalized name with dot syntax.
imports [Dir.Foo]
And it may be the case the Dir
has to start with a capital letter
But that is just a guess from memory and it may not even be implemented, not sure
Yeah that's right
So can I do imports [../../Dir.Foo]
? In my Go adventofcode code, I arrange things like so:
Helper code lives in top-level directories:
/utils
/charmap
/geom
Solution code lives in date-named directories:
/2023/14
I wanted to put Charmap.roc
in /charmap/Charmap.roc
and somehow let my day 14 solution in /2023/14/main.roc
import it…
The key thing here is that the directory has to start with a capital letter. So numbers and lowecase letters wont work because they are not valid identifiers in Roc.
So do you need symlinks if you want to refer to something up the path hierarchy?
Packages can use paths
So if charmap is a full package, you should just use a path to it's main file
If it is just an interface, it has to be equal directory or deeper
Ah, ok. The tutorial left me completely confused on the difference between packages and interfaces. I saw a recommendation here that packages are expected to come from far away, and be downloaded when necessary. But equal-or-deeper means that both (a) organizing your code into subdirectories and (b) having a set of useful interfaces for that codebase, is impossible, and you’d need to use packages even for nearby code.
Seems easy enough to do (lots of code has the platform in the same repo as code and uses “../../platform” to use it.
Which, again, leaves me mystified what interfaces are for :smile:
Probably interfaces should be more flexible. But they are common within a single app for multiple files or within a package
What are they for, though? Are they the only way to split code between files locally to a directory?
Splitting up code, giving a nice public interface, name spacing.
Taking a look at a real package example may help. This is the code for roc-pg a Postgres driver:
https://github.com/agu-z/roc-pg/tree/main/src
It has one package in main and everything else is an interface.
Thanks, I’ll take a look when I get home!
Aaah! That answers my questions! Pg.Batch
(/Pg/Batch.roc
) imports Batch
(/Batch.roc
) with no trouble - the names are based on the root!
Last updated: Jul 06 2025 at 12:14 UTC