'Importing from the contrib library fails
I'm following the TDD book in Idris 2, and the online documentation gives the following advice:
For the
VListview in the exercise 4 after Chapter 10-2 importData.List.Views.Extrafromcontriblibrary.
So I put this import in a source file (example.idr)
import Data.List.Views.Extra
But running idris2 example.idr fails with
Error: Module Data.List.Views.Extra not found
I believe the contrib library is correctly installed, because contrib (0.5.1) appears in the list printed by idris2 --list-packages.
How can Idris 2 be made to accept imports from the contrib library?
Solution 1:[1]
In addition to explicitly providing -p on the command line (as in this answer), you can also define a package for your project, using an IPKG file, wherein you can specify your dependencies.
Minimal example, to be placed in the top-level directory of your project:
package type-driven-development
depends = contrib
Then you can invoke Idris 2 with idris2 --find-ipkg Example.idr, and all of the depends will be included as if you had specified -p for each one.
The Idris 2 CLI also can generate a template IPKG file for you. The idris2 --init command will provide you with interactive prompts in order to fill in some basic values.
Solution 2:[2]
The idris2 binary accepts a --package or -p argument to add a package as a dependency.
Invoking the interpreter with idris2 -p contrib example.idr allows the import to be resolved correctly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shadowtalker |
| Solution 2 | MB-F |
