A representation of CHR rules in Curry, an interpreter for CHR rules based on the refined operational semantics of Duck et al. (ICLP 2004), and a compiler into CHR(Prolog).
To use CHR(Curry), specify the CHR(Curry) rules in a Curry program,
load it, add module CHR
and interpret or compile the rules
with runCHR
or compileCHR
, respectively. This can be done
in one shot with
> pakcs :l MyRules :add CHR :eval 'compileCHR "MyCHR" "MyRules" [rule1,rule2]' :q
Author: Michael Hanus
Version: July 2021
(<=>)
:: Goal a b > Goal a b > CHR a b
Simplification rule. 
(==>)
:: Goal a b > Goal a b > CHR a b
Propagation rule. 
(\\)
:: Goal a b > CHR a b > CHR a b
Simpagation rule: if rule is applicable, the first constraint is kept and the second constraint is deleted. 
(>)
:: CHR a b > Goal a b > CHR a b
A rule with a guard. 
(/\)
:: Goal a b > Goal a b > Goal a b
Conjunction of CHR goals. 
true
:: Goal a b
The always satisfiable CHR constraint. 
false
:: Goal a b
The always unsatisfiable constraint. 
andCHR
:: [Goal a b] > Goal a b
Join a list of CHR goals into a single CHR goal (by conjunction). 
allCHR
:: (a > Goal b c) > [a] > Goal b c
Is a given constraint abstraction satisfied by all elements in a list? 
chrsToGoal
:: [a] > Goal b a
Transforms a list of CHR constraints into a CHR goal. 
toGoal1
:: (a > b) > a > Goal c b
Transform unary CHR constraint into a CHR goal. 
toGoal2
:: (a > b > c) > a > b > Goal d c
Transforms binary CHR constraint into a CHR goal. 
toGoal3
:: (a > b > c > d) > a > b > c > Goal e d
Transforms a ternary CHR constraint into a CHR goal. 
toGoal4
:: (a > b > c > d > e) > a > b > c > d > Goal f e
Transforms a CHR constraint of arity 4 into a CHR goal. 
toGoal5
:: (a > b > c > d > e > f) > a > b > c > d > e > Goal g f
Transforms a CHR constraint of arity 5 into a CHR goal. 
toGoal6
:: (a > b > c > d > e > f > g) > a > b > c > d > e > f > Goal h g
Transforms a CHR constraint of arity 6 into a CHR goal. 
(.=.)
:: a > a > Goal a b
Primitive syntactic equality on arbitrary terms. 
(./=.)
:: a > a > Goal a b
Primitive syntactic disequality on ground(!) terms. 
(.<=.)
:: Ord a => a > a > Goal a b
Primitive lessorequal constraint. 
(.>=.)
:: Ord a => a > a > Goal a b
Primitive greaterorequal constraint. 
(.<.)
:: Ord a => a > a > Goal a b
Primitive lessthan constraint. 
(.>.)
:: Ord a => a > a > Goal a b
Primitive greaterthan constraint. 
ground
:: a > Goal a b
Primitive groundness constraint (useful for guards). 
nonvar
:: a > Goal a b
Primitive nonvar constraint (useful for guards). 
anyPrim
:: (() > Bool) > Goal a b
Embed userdefined primitive constraint. 
solveCHR
:: (Data a, Eq a, Data b, Show b) => [[a] > CHR a b] > Goal a b > Bool
Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and embed this as a constraint solver in Curry. 
runCHR
:: (Data a, Eq a, Data b) => [[a] > CHR a b] > Goal a b > [b]
Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and return the remaining CHR constraints. 
runCHRwithTrace
:: (Data a, Eq a, Data b) => [[a] > CHR a b] > Goal a b > [b]
Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and return the remaining CHR constraints. 
compileCHR
:: String > String > [[a] > CHR a b] > IO ()
Compile a list of CHR(Curry) rules into CHR(Prolog) and store its interface in a Curry program (name given as first argument). 
chr2curry
:: (Data a, Eq a) => Goal a b > Bool
Transforms a primitive CHR constraint into a Curry constraint. 
The basic data type of Constraint Handling Rules.
Constructors:
A CHR goal is a list of CHR constraints (primitive or userdefined).
Constructors:
Simplification rule.

Propagation rule.

Simpagation rule: if rule is applicable, the first constraint is kept and the second constraint is deleted.

A rule with a guard.

Conjunction of CHR goals.

The always satisfiable CHR constraint.

The always unsatisfiable constraint.

Is a given constraint abstraction satisfied by all elements in a list? 
Transforms a list of CHR constraints into a CHR goal. 
Transforms a ternary CHR constraint into a CHR goal. 
Transforms a CHR constraint of arity 4 into a CHR goal. 
Transforms a CHR constraint of arity 5 into a CHR goal. 
Transforms a CHR constraint of arity 6 into a CHR goal. 
Primitive syntactic equality on arbitrary terms.

Primitive syntactic disequality on ground(!) terms.

Primitive lessorequal constraint.

Primitive greaterorequal constraint.

Primitive lessthan constraint.

Primitive greaterthan constraint.

Primitive groundness constraint (useful for guards).

Primitive nonvar constraint (useful for guards).

Embed userdefined primitive constraint.

Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and embed this as a constraint solver in Curry. If userdefined CHR constraints remain after applying all CHR rules, a warning showing the residual constraints is issued. 
Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and return the remaining CHR constraints. 
Interpret CHR rules (parameterized over domain variables) for a given CHR goal (second argument) and return the remaining CHR constraints. Trace also the active and passive constraints as well as the applied rule number during computation. 
Compile a list of CHR(Curry) rules into CHR(Prolog) and store its interface in a Curry program (name given as first argument). The second argument is the name of the module containing the CHR(Curry) rules. 