Home

Awesome

Compiling to categories

Build Status

Experimenting (again) with constrained categories, as well as Haskell to hardware, automatic differentiation, interval analysis, and other interpretations. See the paper Compiling to categories.

You will need to have GraphViz installed, with its dot command on your execution path.

To run miscellaneous examples:

stack build :misc-examples

There are several more commented-out examples in examples/test/Examples.hs. You can fiddle with comments to change the collection of examples compiled. That module also serves as an example to copy and make your own examples.

For the graphics examples, instead run

stack build :graphics-examples

There are more examples in graphics/test/Examples.hs.

Note: as of 2018-08-30, the graphics examples work under GHC 8.0.2 and 8.2.2 but not later, because of dependency on language-glsl. (See this issue.)

The SMT examples are disabled by default, because they rely on installing the Z3 SMT solver (with installation etc described here). To enable some of those examples, install Z3, uncomment them in examples/test/Examples.hs, and run as follows:

stack build :misc-examples --flag concat-examples:smt

If you tweak the source and want to make a pull request, please also run the gold tests:

stack build :gold-tests

Sometimes the generated categorical expressions change with GHC versions while preserving semantics. In such cases, it might be unclear whether something broke or not.

Troubleshooting

"dot: command not found"

Install GraphViz.

I can't install netlist-to-verilog with cabal new-build or cabal install

https://github.com/ku-fpg/netlist is the repo that includes the offending package. To get things started do git clone https://github.com/ku-fpg/netlist.git ../netlist-kit-kufp/

I get an error along the lines of "Oops: toCcc' called"

The plugin works via two kinds of rewrite rules: some specified via RULES pragmas, in the modules ConCat.AltCat and ConCat.Rebox, and a "builtin" rule, which is Haskell code that explicitly manipulates Core, in ConCat.Plugin. An run-time error of the form "Oops: toCcc' called" occurs if the plugin was not able to transform away all uses of the pseudo-function toCcc' (which has no implementation) via the rules.

Therefore:

import ConCat.AltCat ()
import ConCat.Rebox ()

Example of ghc compilation:

ghc -O -fplugin=ConCat.Plugin YourModule.hs

Unfortunately, this library doesn't (yet) work when called from ghci.

Plugin flags

You can get more info about plugin failures by providing some flags in the module being compiled with the plugin. The current options:

{-# OPTIONS_GHC -fplugin-opt=ConCat.Plugin:trace #-}
{-# OPTIONS_GHC -fplugin-opt=ConCat.Plugin:showResiduals #-}
{-# OPTIONS_GHC -fplugin-opt=ConCat.Plugin:showCcc #-}

Some applications

Working:

In progress:

Others: