This project implements a transpiler to minify a simple subset of the Haskell language.
graph LR
I(Source) --> G(GHCHaskell)
G --> S(SimpleHaskell)
S --> M(Minifier)
M --> O(Source)
The project is composed of three modules:
- GHCHaskell: parses and decodes Haskell source with ghc-lib-parser.
- SimpleHaskell: defines a simple Expr data type.
- Minifier: transforms and renders the Expr.
The Minifier does the following transformation:
- Combine repeated names when possible.
- Rename binder to single letter name.
- Inline single-use variable.
- Remove unused space.
- Pack the lines to fit a column limit.
$ cabal run << EOF
module Demo where
render 0 = putStrLn "game-over"
render score
| score >= 1, score <= 2 = pure ()
| otherwise = putStrLn ("score: " ++ show score)
eval pos | pos > 42 = True
| otherwise = False
EOF
a 0=d"game-over";
a e|e>=1,e<=2=pure()|c=d("score: "++show e);
b e|e>42=c|c=False;
c=True;
d=putStrLn
Checkout the examples for more minification demos.
Contributions and bug reports are welcome! The implementation works ok for the examples, and I'd be happy to integrate changes to support other usage.
To work on this project you need a Haskell toolchain: get-started.
Run the ./bin/run-tests
script to validate a commit.