Commit b33944ca by Michael Hanus

parent a40cca66
 ... ... @@ -5,13 +5,13 @@ --- as primitive constraints in CHR(Curry) --- --- @author Michael Hanus --- @version October 2016 --- @version July 2021 ---------------------------------------------------------------------- {-# OPTIONS_CYMAKE -Wno-incomplete-patterns -Wno-missing-signatures #-} import CHR import qualified List import qualified Data.List ---------------------------------------------------------------------- -- Finite domain constraints in CHR (influence from SWI-Prolog manual) ... ... @@ -19,8 +19,8 @@ data FDom = Dom Int [Int] | Diff Int Int dom = toGoal2 Dom diff = toGoal2 Diff intersect xs ys zs = anyPrim (\() -> zs =:= List.intersect xs ys) delete x ys zs = anyPrim \$ \() -> zs =:= List.delete x ys intersect xs ys zs = anyPrim (\() -> zs =:= Data.List.intersect xs ys) delete x ys zs = anyPrim \$ \() -> zs =:= Data.List.delete x ys member x xs = anyPrim \$ \() -> contains x xs where contains z (y:ys) = z=:=y ? contains z ys ... ... @@ -93,4 +93,5 @@ main55 [l1,l2,l3,l4] = labeling runFD2 \$ diff l2 l4 /\ diff l3 l4 /\ l2 .=. 3 -- fix color of L2 compileFD = compileCHR "FDCHR" [dom1,dom2,dom3,dom4,diff1,diff2,diff3,diff4] compileFD = compileCHR "FDCHR" "FD" [dom1,dom2,dom3,dom4,diff1,diff2,diff3,diff4]
 ... ... @@ -2,7 +2,7 @@ --- CHR(Curry): using CHR to compute Fibonacci numbers with tabling --- --- @author Michael Hanus --- @version February 2015 --- @version July 2021 ---------------------------------------------------------------------- {-# OPTIONS_CYMAKE -Wno-incomplete-patterns -Wno-missing-signatures #-} ... ... @@ -38,5 +38,5 @@ runFib2 = runCHR [dup,fib1,fibn,addrule] main41 x = runFib2 \$ fib 7 x --> x=21 compileFib = compileCHR "FIBCHR" [fibo1,fibo2,fibo3,addrule] compileFib = compileCHR "FIBCHR" "Fib" [fibo1,fibo2,fibo3,addrule] -- solveCHR \$ fib 20 x where x free
 ... ... @@ -2,7 +2,7 @@ --- CHR(Curry): use CHR to compute the greatest common divisor --- --- @author Michael Hanus --- @version February 2015 --- @version July 2021 ---------------------------------------------------------------------- {-# OPTIONS_CYMAKE -Wno-incomplete-patterns -Wno-missing-signatures #-} ... ... @@ -28,5 +28,5 @@ main30 = runGCD \$ gcd 16 /\ gcd 28 --> gcd 4 main31 = runGCD \$ gcd 206 /\ gcd 40 --> gcd 2 ---------------------------------------------------------------------- compileGCD = compileCHR "GCDCHR" [gcda,gcd2] compileGCD = compileCHR "GCDCHR" "GCD" [gcda,gcd2] -- solveCHR \$ gcdanswer x /\ gcd 206 /\ gcd 40 where x free