Stream: beginners

Topic: stop one function from being exposed


view this post on Zulip Anton (Feb 23 2026 at 14:34):

By default all functions of a module are exposed, is there an easy way to hide(not expose) a single function?

view this post on Zulip Richard Feldman (Feb 23 2026 at 14:50):

it's only functions associated with the type that get exposed

view this post on Zulip Richard Feldman (Feb 23 2026 at 14:50):

so if you write a normal top-level function, it's private to the module

view this post on Zulip Fabian Schmalzried (Feb 23 2026 at 14:54):

That means I cannot have MyModule.some_private_stuff(...) but only MyModule -> some_private_stuff(...), right? That actually makes it clear when calling something if it is public or not. Maybe that is even kind of nice.

view this post on Zulip Anton (Feb 23 2026 at 15:09):

Richard Feldman said:

so if you write a normal top-level function, it's private to the module

If I add a top-level type alias with a name different from the filename is that private to the module too?

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:37):

yep!

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:37):

only things associated with the type are exposed

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:38):

the mental model is supposed to be that you don't "expose" or "hide" things anymore

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:38):

rather, import Foo imports the Foo type from Foo.roc and now you can access associated items on the Foo type as normal

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:38):

and that's it

view this post on Zulip Richard Feldman (Feb 23 2026 at 15:39):

so if I'm in Foo.roc, anything I don't make an associated item on Foo can't be seen by other modules because import Foo is only concerned with the Foo type I defined

view this post on Zulip Anton (Feb 24 2026 at 16:10):

These kind of private functions are very useful to leave "unimplemented", where the platform provides the implementation. Much easier than all the splitting and duplicating we were doing with e.g. Cmd.roc and InternalCmd.roc


Last updated: Mar 20 2026 at 12:28 UTC