PolyP reference manual

This text is a draft reference manual for PolyP. (Patrik Jansson, 1999)

Flag summary

Usage:
polyp [--version] [-v] {-p Preludefile.hs} {-r f[:D]} [polypcode.phs]
--version
Prints the PolyP compiler version and exits
-v
Verbatim - print information about the compiler phases while compiling
-p file
Read explicit type information from file before starting.
-r value[:type constructor|all]
Start polytypic instantiation from value (default is from main). If value is polytypic, the desired datatype constructor D must be given.
If polyp is compiled with hbc, prepend a dash ('-') to the command line. (Or compile with polyp with make hbc "hbc=hbc -noflags".)

Compiler phases

Invoking the compiler phases:
  chase {-i ImportDir} PolyPModule.phs  > PolyPcode.Phs

  polyp [-v] {-p ExplTypes.hs} {-r f[:D]}] PolyPcode.Phs > Haskellcode.Hs

  [cat Prefix.hs Haskellcode.Hs         > Haskellcode.hs]
The import chaser chase takes a polytypic program module and inlines the text of all imported modules (recursively). The output consists of one big module of the concatenated texts of the involved modules and should normally be directed to a file (ending in .Phs - a big 'P' to denote a big PolyP file). If your input consists of just one file and does not need any others the chase is unnecessary. (But unless you paste the polytypic prelude into your file by hand, you will virtually always need chase.) The flag -i can be used (any number of times) to specify directories that are to be searched for the imported modules. For convenience the polytypic library directory POLYPDIR/polylib is always implicitly included.

The main translation phase

The main compilation (or translation) is done by calling polyp P.Phs. It type checks the input file P.Phs and generates the instances of all polytypic functions that are used in the code reachable from the definitions of the start values. By default there is one start value - main - but the flag -r value[:D|all] can be used (any number of times) to specify other start values. If the start value is polytypic, it must be instatiated to a regular type constructor (D) (or to all regular type constructors) given after the colon.

The output is Haskell code and can be loaded in hugs or compiled with a Haskell compiler. Sometimes the generated code is rejected as a Haskell program due to the lack of explicit type declarations of top level overloaded function. In this case these declarations have to be supplied by hand. The simplest way to do this is to put them in a separate file and then cat it together with the polyp output. If the flag -v (verbose) is used, the different phases of the PolyP compilation give progress reports in a Haskell comment in the output file:

The error messages from PolyP unfortunately don't give line numbers where the error occurred, but it is often possible to pinpoint the location quite accurately by studying the reports: If a type error occurs, check to see what function is the last one before the error in the type report and look up the name following this one in the dependency report. This definition is probably the culprit.

The flag -p is used when you want to use Haskell functions that are not in the built in part of the Haskell prelude. If you list the types of these functions in a file ExplTypes.hs and call PolyP with polyp -p ExplTypes.hs PolyPCode.Phs you can use the listed functions in the definitions in PolyPCode.Phs. Note that the file ExplTypes.hs must contain only explicit type declarations, and that these are only read by PolyP, not included in the output. The definitions of these functions should be placed in a separate file and prepended to the PolyP output or loaded in hugs in some other way.

Polytypic program construction tips

When writing polytypic programs with PolyP there are some things to think about:

A sample Makefile

A sample Makefile for using PolyP to translate polytypic programs to Haskell is in ../test/polyp.mk.
Last modified: Tue Jun 5 10:05:27 MET DST 2001 by
Patrik Jansson / patrikj@cs.chalmers.se