Is there an example for a working LibraryModule somewhere?
- meschOP
I tried to create a library module according to the documentation here.
My understanding is that a library is just any
damlfile that contains only imports, and then I would import that file instead of importing all the imported files where I want to use that library.So I try to bundle a few files like
Portfolio.damltogether into a library calledArbo.daml.I tried this at first:
module Arbo where import qualified Portfoliothen this, after the error message that the import is redundant:
module Arbo where import qualified Portfolio ()and also this:
module Arbo where import qualified Portfolio (Contract, Info, Key)None of this works.
I get error message about those imports in the library:
Message: ./Arbo.daml:5:1: error: The qualified import of ‘Portfolio’ is redundant except perhaps to import instances from ‘Portfolio’ To import instances alone, use: import Portfolio()If I follow the advice from the error message, I get this error from where I try to use the library:
Message: ./Arbo_Test.daml:96:40: error: Not in scope: data constructor ‘Portfolio.Info’ No module named ‘Portfolio’ is imported.I think an actual working example somewhere would help me understand this. Is there one?
Thanks a lot,
mesch. - mesch
One thing that I can see is that qualified imports don’t work transitively. I chose that naming pattern because I found it awfully confusing if the module has the same name as something inside it, so I made sure each carries its own disjoint part of the meaning.
Maybe that’s not idiomatic, I have no idea. Recommendations appeciated.
- cocreature
The docs you found here are unfortunately quite out of date, I’ve reached out to the responsible team to update them.
The good thing is you don’t actually need to do any of that bundling. Just define your code, make sure your files are all in the
sourcedirectory in yourdaml.yaml, rundaml buildand then use the DAR indata-dependenciesof another project.The
LibraryModules.damlpart comes from a time whensourceneeded to reference a single file rather than a directory. In that case, it was common to have oneLibraryModules.damlfile that referenced all other files. Luckily, you can just specify a directory these days and skip all of that.