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
data CHR dom chr
The basic data type of Constraint Handling Rules.
data Goal dom chr
A CHR goal is a list of CHR constraints (primitive or user-defined).
(<=>)
:: 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.
The always satisfiable CHR constraint.
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.
Primitive syntactic equality on arbitrary terms.
Primitive syntactic disequality on ground(!) terms.
(.<=.)
:: Ord a => a -> a -> Goal a b
Primitive less-or-equal constraint.
(.>=.)
:: Ord a => a -> a -> Goal a b
Primitive greater-or-equal constraint.
(.<.)
:: Ord a => a -> a -> Goal a b
Primitive less-than constraint.
(.>.)
:: Ord a => a -> a -> Goal a b
Primitive greater-than constraint.
Primitive groundness constraint (useful for guards).
Primitive nonvar constraint (useful for guards).
anyPrim
:: (() -> Bool) -> Goal a b
Embed user-defined primitive constraint.
solveCHR
:: (Data a, Data b, Eq a, 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. If user-defined CHR constraints remain after applying all CHR rules, a warning showing the residual constraints is issued.
runCHR
:: (Data a, Data b, Eq a) => [[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, Data b, Eq a) => [[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. Trace also the active and passive constraints as well as the applied rule number during computation.
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). The second argument is the name of the module containing the CHR(Curry) rules.
chr2curry
:: (Data a, Eq a) => Goal a b -> Bool
Transforms a primitive CHR constraint into a Curry constraint. Used in the generated CHR(Prolog) code to evaluated primitive constraints.