Stream: beginners

Topic: ✔ How to import from a package in a module


view this post on Zulip Alex Nuttall (May 31 2024 at 21:27):

I feel like I'm missing something obvious, but how do I import and use e.g.roc-json outside the app entrypoint file? I'm not finding many examples.

view this post on Zulip Isaac Van Doren (Jun 01 2024 at 00:02):

You reference the same package shorthand used in the main file. So if your main.roc has

json: “https://….

Then you can do

import json.Core

view this post on Zulip Alex Nuttall (Jun 01 2024 at 09:17):

OK I got it, thanks

main.roc

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

import pf.Stdout
import Mod

main =
    Mod.stringify {}
    |> Str.fromUtf8
    |> Result.withDefault ""
    |> Stdout.line

Mod.roc

module [stringify]

import json.Json

stringify = \rec -> Encode.toBytes rec Json.utf8

view this post on Zulip Notification Bot (Jun 01 2024 at 09:17):

Alex Nuttall has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC