PolyP reference manual

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

Compiler phases

Invoking the compiler phases:
  chase [-i ImportDir] PolyPModule.phs  > PolyPcode.Phs

  polyp [-p ExplTypes.hs] 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. The polytypic library directory POLYPDIR/polylib is a typical candidate here.

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 main. 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. 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:
Last modified: Fri Aug 7 10:58:48 MET DST 1998 by
Patrik Jansson / patrikj@cs.chalmers.se