Importing a Package from a Module

You probably know how to use a package in an app, for example with the unicode package:


app [main!] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.18.0/0APbwVN1_p1mJ96tXjaoiUCr8NBGamr8G8Ac_DrXR-o.tar.br",
    unicode: "https://github.com/roc-lang/unicode/releases/download/0.1.2/vH5iqn04ShmqP-pNemgF773f86COePSqMWHzVGrAKNo.tar.br",
}

But how can you use a package in a module? All dependencies go in the app file!

So we have the app file just like before:

### start snippet header
app [main!] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.18.0/0APbwVN1_p1mJ96tXjaoiUCr8NBGamr8G8Ac_DrXR-o.tar.br",
    unicode: "https://github.com/roc-lang/unicode/releases/download/0.1.2/vH5iqn04ShmqP-pNemgF773f86COePSqMWHzVGrAKNo.tar.br",
}
### end snippet header

import pf.Stdout
import Module

main! = \_args ->
    Stdout.line! (Inspect.toStr (Module.split_graphemes "hello"))

And we put the unicode import in the module:

module [split_graphemes]

import unicode.Grapheme

split_graphemes = \string -> Grapheme.split string

Output

Run this from the directory that has main.roc in it:

$ roc main.roc
(Ok ["h", "e", "l", "l", "o"])