Experimenting (again) with constrained categories, as well as Haskell to hardware, automatic differentiation, interval analysis, and other interpretations. See the paper Compiling to categories.
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.
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
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:
- Be sure to import the
ConCat.AltCat
andConCat.Rebox
modules, e.g.,
import ConCat.AltCat ()
import ConCat.Rebox ()
-
Remember to tell ghc to use the plugin with the option
-fplugin=ConCat.Plugin
. -
Remember to turn on optimization, which enables the firing of the rules (e.g.,
-O
or-O2
). -
Sometimes you also need to import
GHC.Generics
with a few constructors exposed (e.g.,U1
,Par1
,(:*:)
, andComp1
) so that Core casts can be successfully translated to categorical form (viaCoercible
). This requirement is especially unfortunate because the need to import has nothing to do with explicit use of those constructors in code that you write, and because following this advice leads to compiler warnings about unused imports. I hope to find an alternative method of translating coercions.
Example of ghc compilation:
ghc -O -fplugin=ConCat.Plugin YourModule.hs
Unfortunately, this library doesn't (yet) work when called from ghci.
Working:
- Circuit graphs
- Automatic differentiation
- GLSL for graphics
- Interval analysis
- Incremental computation
- SMT (satisfy modulo theories), with John Wiegley
In progress:
- Polynomials
- Demand analysis for strictness.
- Functions with some special cases like constant, linear, polynomial, as well as the general case
Others:
- Something about language recognition, such as regular languages
- Various semirings, including shortest/longest paths
- Probabilistic programming and other wrappings of monadic interfaces
- Memoization at every stage. With what benefit?
- AFRP