Skip to content
CCPEDIAby Unity Nodes
App Development

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

3 posts431 views4 likesLast activity Dec 2021

  1. georgOP

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

  2. cocreature 1

    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.

  3. Luciano 3

    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