Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Can I limit the templates, types, and functions exported from a module?Forum ↗

Can I limit the templates, types, and functions exported from a module?

App Development3 posts407 views4 likesLast activity Dec 2021
GE
georgOP
Dec 2021

…such that consuming code can only import the ones exported but not other ones? As a way to keep code private to a module.

CO
cocreature
Dec 2021

It somewhat depends on what your goal is. There is no way to limit exports in Daml-LF or across data-dependencies so if your goal is to enforce internal invariants or something along those lines you’re out of luck.

You can limit exports in Daml within a package (and within dependencies) using Haskell export lists, e.g.,

module M (f) where

will only export the function f. See 5 Modules for more details on those.

Given that they are not respected in Daml-LF those only serve as guidance to users not as a way to enforce invariants so I view that more as documentation on the intended API of a module.

LU
Luciano
Dec 2021

See this post about using namespaces cleverly:

https://discuss.daml.com/t/managing-namespaces-in-daml

And also this for a discussion of enforcement of scope through the API, which I think you may be alluding to:

https://discuss.daml.com/t/should-runtime-api-respect-namespace-scopes

← Back to Discussions