Import from Directory
To import a module that lives inside a Directory:
import Dir.Hello exposing [hello]
You can also do:
import Dir.Hello as Hello
Or:
import Dir.Hello
Note that in this last case you will need to use Dir.Hello
in your code, for example: Dir.Hello.hello "World!"
.
Code
Dir/Hello.roc:
# Only what's listed here is accessible to other modules module [hello] hello : Str -> Str hello = |name| "Hello ${name} from inside Dir!"
main.roc:
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" } import cli.Stdout import Dir.Hello exposing [hello] main! = |_args| # here we're calling the `hello` function from the Hello module Stdout.line!(hello("World"))
Output
Run this from the directory that has main.roc
in it:
$ roc main.roc Hello World from inside Dir!