ychr: A Constraint Handling Rules compiler with multiple backends
Constraint Handling Rules (CHR) is a declarative, rule-based language for writing constraint solvers, type inferencers, and other rule-driven logic. A program is a set of rules that rewrite a multiset of constraints until no rule applies.
YCHR compiles standard CHR — Prolog-compatible syntax, extended with Erlang-style user-defined functions and an optional gradual type system — to a small abstract VM, which is either interpreted directly in Haskell or translated to Scheme.
Using YCHR as a Haskell library
The common compile-and-query path is available from a single import:
{-# LANGUAGE OverloadedStrings #-}
import YCHR
main :: IO ()
main = do
result <- compileFiles True ["Order.chr"]
case result of
Left err -> putStr (displayError err)
Right (cp, _warnings) -> do
r <- runQueryCompiled cp goal "R"
print (r :: Either ConvertError Int)
where goal = CompoundTerm (Unqualified "compute") [VarTerm "R"]Compile a .chr module once, then feed it Haskell values and decode its
answers back through the ToTerm / FromTerm bridge. Haskell functions
can be exposed to CHR programs as host calls, and programs can be built
in Haskell directly with the YCHR.DSL combinators instead of parsed
from source.
For a worked example — a lambda-calculus type inferencer written in CHR and driven from Haskell — see the embedding guide: https://github.com/lortabac/ychr/blob/master/docs/how-to/embed-a-chr-module.md.
Status
Early release. The Haskell interpreter and the Scheme backend work; the
JavaScript backend and most of the optimization catalogue are not yet
implemented. The ychr command-line compiler and REPL ship with this
package. Compiling to Scheme additionally requires the runtime from a
source checkout. Full status in the roadmap:
https://github.com/lortabac/ychr/blob/master/docs/roadmap.md.
Modules under YCHR.Internal are implementation details, exposed for
documentation purposes only, and are not covered by the package version
policy.
AI disclosure
This project has been developed with the help of large language models.
[Skip to Readme]
Modules
[Index] [Quick Jump]
- YCHR
- YCHR.Convert
- YCHR.DSL
- Internal
- Backend
- YCHR.Internal.Collect
- YCHR.Internal.Collected
- YCHR.Internal.Compile
- YCHR.Internal.Constructors
- YCHR.Internal.Desugar
- YCHR.Internal.Desugared
- YCHR.Internal.Diagnostic
- YCHR.Internal.Display
- YCHR.Internal.Exhaustiveness
- YCHR.Internal.Loc
- YCHR.Internal.Meta
- YCHR.Internal.PExpr
- YCHR.Internal.Parsed
- YCHR.Internal.Parser
- Parsing
- YCHR.Internal.Pretty
- YCHR.Internal.Rename
- YCHR.Internal.Repl
- YCHR.Internal.Resolve
- YCHR.Internal.Resolved
- Runtime
- YCHR.Internal.Runtime.Error
- YCHR.Internal.Runtime.History
- YCHR.Internal.Runtime.Interpreter
- YCHR.Internal.Runtime.Monad
- YCHR.Internal.Runtime.Reactivation
- YCHR.Internal.Runtime.Registry
- YCHR.Internal.Runtime.Session
- YCHR.Internal.Runtime.Store
- YCHR.Internal.Runtime.Trace
- YCHR.Internal.Runtime.Types
- YCHR.Internal.Runtime.Var
- YCHR.Internal.SExpr
- YCHR.Internal.StdLib
- YCHR.Internal.TypeCheck
- YCHR.Internal.Types
- YCHR.Internal.VM
- YCHR.Run
- YCHR.Types
Flags
Manual Flags
| Name | Description | Default |
|---|---|---|
| examples | Build the example executables. | Disabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- ychr-0.1.0.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
| Versions [RSS] | 0.1.0.0 |
|---|---|
| Change log | CHANGELOG.md |
| Dependencies | ansi-terminal (>=0.11 && <1.2), base (>=4.18 && <4.22), containers (>=0.6 && <0.9), directory (>=1.3 && <1.4), filepath (>=1.4 && <1.6), haskeline (>=0.8 && <0.9), optparse-applicative (>=0.17 && <0.20), parsec (>=3.1 && <3.2), template-haskell (>=2.20 && <2.24), text (>=2.0 && <2.2), transformers (>=0.6 && <0.7), ychr [details] |
| Tested with | ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.2, ghc ==9.12.4 |
| License | BSD-3-Clause |
| Copyright | (c) 2026 Lorenzo Tabacchini |
| Author | Lorenzo Tabacchini |
| Maintainer | lortabac@gmx.com |
| Uploaded | by lortabac at 2026-08-13T20:08:53Z |
| Category | Language |
| Home page | https://github.com/lortabac/ychr |
| Bug tracker | https://github.com/lortabac/ychr/issues |
| Source repo | head: git clone https://github.com/lortabac/ychr.git |
| Distributions | |
| Executables | stlc-typechecker, ychr |
| Downloads | 2 total (2 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating | |
| Status | Docs uploaded by user Build status unknown [no reports yet] |