Stream: beginners

Topic: Importing Module from a Sub-Directory


view this post on Zulip Sajjad Naveed (Jun 08 2024 at 14:45):

I think I read in some place that it's possible to import a Module from a sub-directory. I have tried to do it a few different ways but unfortunately none have succeeded. Is it possible? How?

view this post on Zulip Anton (Jun 08 2024 at 15:20):

Hi @Sajjad Naveed,
Can you share your specific project structure?
Is it like this?

myProject/
├── main.roc
└── subdir
    └── Module.roc

view this post on Zulip Sajjad Naveed (Jun 08 2024 at 15:52):

Yeah @Anton , It's pretty much exactly like how you described it.

view this post on Zulip Anton (Jun 08 2024 at 16:09):

You can do that like this:

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task
import Subdir.Hello
# You can also do:
# import Subdir.Hello as Hello
# Or:
# import Subdir.Hello exposing [hello]

main =
    Stdout.line! (Subdir.Hello.hello "World")

I noticed that starting with a lowercase letter (e.g. "import subdir.Hello")causes roc check to hang, I'll make an issue for that.

I'll also make an official example for how to do Subdir imports like this.

view this post on Zulip Anton (Jun 08 2024 at 16:11):

Turns out we already have an issue for the hang #6388

view this post on Zulip Agus Zubiaga (Jun 08 2024 at 16:12):

I'll have a fix for this soon!

view this post on Zulip Sajjad Naveed (Jun 08 2024 at 17:18):

Thanks guys :raised_hands:


Last updated: Jul 05 2025 at 12:14 UTC