5 Managing Curry Packages

5.3 Developing Applications and Packages

If one wants to implement an application in Curry which uses other Curry packages, one should create a package for this application in order to specify all dependencies so that they can be managed by CPM. The easiest way to create a new package is to use CPM’s new command with the name of the new package:

> cypm new myproject

This creates a new directory myproject in which the application can be developed. The generated file structure is as follows:

   myproject
   |-- LICENSE
   |-- package.json
   |-- README.md
   |-- src
       |-- Main.curry

This represents the minimal structure of a reasonable package (so that it could later be published). The file README.md should contain a description of the package in plain text or markdown syntax. The LICENSE file is BSD-3 but could be changed. The source code of the package must be stored in directory src and might of consist of an arbitrary number of modules.

The file package.json is the most important one for managing packages. It is a JSON file containing the metadata of the package, like its name, version, author, synopsis, etc. The detailed description of all possible metadata fields can be found in CPM’s user manual. One has to modify this file according to the requirements of the new application. In particular, one has to specify dependencies on other packages by modifying the field dependencies in the package.json file,22 2 One could also use the command “cypm add -d PACKAGE” to add new dependencies in this file. e.g.:

   {
     ...,
     "dependencies": {
       "base": ">= 3.0.0, < 4.0.0",
       "json": "~> 3.0.0"
     }
   }

After modifying the metadata, one can run

> cypm install

(inside the package directory myproject) to resolve, download, and install all dependencies of the current package. Then one can invoke PAKCS and use the modules of all specified packages.

When the development of the application is completed, one can specify the name of the main module and the executable to be generated in the file package.json as field executable:

   {
     ...,
     "executable": {
       "name": "myexec",
       "main": "Start"
      }
   }

The name of the executable must be defined (with key name) whereas the name of the main module (key main) is optional (if it is missing, the name Main is taken). The main module must export a function

main :: IO ()

which starts the application. If a package contains an executable specification, the command

> cypm install

also compiles the main module and installs the executable in the default directory $HOME/.cpm/bin (see Section 5.2).