Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rizo/ppx_rule
Compile-time rewrite rules for OCaml
https://github.com/rizo/ppx_rule
Last synced: about 1 month ago
JSON representation
Compile-time rewrite rules for OCaml
- Host: GitHub
- URL: https://github.com/rizo/ppx_rule
- Owner: rizo
- License: bsd-2-clause
- Created: 2016-01-15T04:03:09.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-15T14:29:33.000Z (almost 9 years ago)
- Last Synced: 2023-03-11T03:57:02.023Z (almost 2 years ago)
- Language: OCaml
- Homepage:
- Size: 15.6 KB
- Stars: 18
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Compile-time optimization rules
This syntax extension implements compile-time rewrite rules to offer a powerful and flexible way to optimise your programs.
Consider the following simple examples:
```ocaml
(* Helper functions *)let sum x y = x + y
let hello who = "Hello, " ^ who(* Rules *)
let%rule sum 2 2 = 5
let%rule hello "rule" = "rules rock!"
let%rule sqrt 100000000000.0 = 316227.766017let replaced = (sum 2 2, hello "rule", sqrt 100000000000.0)
let computed = (sum 1 1, hello "world", sqrt 99.0)
```The syntax processor will replace the known patterns during the compilation time.
After the application the resulting code will look like this:```ocaml
let sum x y = x + y
let hello who = "Hello, " ^ wholet replaced = (5, "rules rock!", 316227.766017)
let computed = (sum 1 1, hello "world", sqrt 99.0)
```Note that the rules disappear during the compliation, so no runtime overhead is added to the program.
For more examples see the `tests` directory and for build options run `make help`.
## Known Limitations
- Parametric rules are not implemented yet.
- The visibility of the rules is limited to the module where they were declared.
- Recursive rules may have unexpected results.## Project Status
This project is still in development and at this point should be considered a proof of concept, please use with care.
This syntax extension was inspired by [Rule pragma](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/rewrite-rules.html) for Haskell.