Stream: beginners

Topic: Namespacing


view this post on Zulip Ryan Bates (Dec 11 2023 at 19:09):

Is there any way to namespace functions and values within the same file? Something like this.

main = Stdout.line "Part 1: \(Part1.run inputStr)"

namespace Part1
    run = \input -> ...

I know I can create a Part1.roc file, but sometimes it's nice to organize things inline and then refactor into an external file as needed.

view this post on Zulip Anton (Dec 12 2023 at 10:34):

We don't have anything exactly like that but you could do:

main =
    part1.greet "Ryan"

part1 = {
    hey,
    greet
}

hey = Stdout.line "hey"

greet = \name -> Stdout.line "Hello, \(name)!"

view this post on Zulip Brendan Hansknecht (Dec 12 2023 at 15:45):

Probably a bit better name spacing is to fully nest the functions so they don't take up top level names and can be shared between parts:

part1 =
    run = \input -> ...

    # other funcs

    # exposed functions
    { run, ... }

Last updated: Jul 06 2025 at 12:14 UTC