Giter Site home page Giter Site logo

well-typed / concat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from compiling-to-categories/concat

0.0 4.0 0.0 10.84 MB

Constrained categories

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

Shell 0.46% Haskell 96.91% JavaScript 1.61% CSS 0.20% Verilog 0.82%

concat's Introduction

Constrained 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.

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

Troubleshooting

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.

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

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.