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!] {
    cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
    unicode: "https://github.com/roc-lang/unicode/releases/download/0.3.0/9KKFsA4CdOz0JIOL7iBSI_2jGIXQ6TsFBXgd086idpY.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!] {
    cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
    unicode: "https://github.com/roc-lang/unicode/releases/download/0.3.0/9KKFsA4CdOz0JIOL7iBSI_2jGIXQ6TsFBXgd086idpY.tar.br",
}
### end snippet header

import cli.Stdout
import Module

main! = |_args|
    Module.split_graphemes("hello")
    |> Inspect.to_str
    |> Stdout.line!

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"])