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.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.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.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.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 = Stdout.line! (Inspect.toStr (Module.splitGraphemes "hello"))
And we put the unicode import in the module:
module [splitGraphemes] import unicode.Grapheme splitGraphemes = \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"])