Is there an example for a working LibraryModule somewhere?

I tried to create a library module according to the documentation here.

My understanding is that a library is just any daml file 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.daml together into a library called Arbo.daml.

I tried this at first:

module Arbo where

import qualified Portfolio

then 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.

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.

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 source directory in your daml.yaml, run daml build and then use the DAR in data-dependencies of another project.

The LibraryModules.daml part comes from a time when source needed to reference a single file rather than a directory. In that case, it was common to have one LibraryModules.daml file that referenced all other files. Luckily, you can just specify a directory these days and skip all of that.