GithubHelp home page GithubHelp logo

templatek / concat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from compiling-to-categories/concat

0.0 0.0 0.0 10.97 MB

Compiling to Categories

Home Page: http://conal.net/papers/compiling-to-categories

License: BSD 3-Clause "New" or "Revised" License

Haskell 94.75% JavaScript 1.58% CSS 0.74% Verilog 0.81% Shell 0.45% HTML 1.67%

concat's Introduction

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:

  • Be sure to import the ConCat.AltCat and ConCat.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, (:*:), and Comp1) so that Core casts can be successfully translated to categorical form (via Coercible). 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.

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 #-}
  • trace: Generate lots of output as (small) transformations happen.
  • showResiduals: A residual toCcc' call is one that the plugin did not manage to eliminate. Since the toCcc' pseudo-function has no implementation, residuals often result in a run-time error message.
  • showCcc: Show the Core for the whole module being compiled, at the end of the toCcc phase and before the final GHC passes.

Some applications

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

concat's People

Contributors

adamgundry avatar capn-freako avatar cartazio avatar conal avatar eschnett avatar guibou avatar isovector avatar kenranunderscore avatar kosmikus avatar osa1 avatar sellout avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.