]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl
(refs #7250) CHR rules modularization (first working version)
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / CHR5.scl
index e3c8b8c27d5292acec9abaadaa0fe45336ed8d2b..00ca32bec06f5b887afd13e5b3a7d1800a939ead 100644 (file)
@@ -1,16 +1,34 @@
+module {
+    export = [main],
+    chr
+}
+
 import "StandardLibrary"
 
-topologicalSort :: Show a => [(a,a)] -> <Proc> [a]
-topologicalSort dependencies = MList.freeze answer
-  where
-    answer = MList.create ()
+ruleset IntegerSet where
+    constraint Element Integer
+    // Set may not contain duplicates
+    Element ?x => print "added \(?x)"
+    -Element ?x, Element ?x => print "removed duplicate \(?x)"
     
-    (?x,?y) <- dependencies           =>  print "RULE 1, x=\(?x), y=\(?y)", Dep ?x ?y, InDegree ?x 0, InDegree ?y 1
-    -InDegree ?x ?a, -InDegree ?x ?b  =>  print "RULE 2, x=\(?x), a=\(?a), b=\(?b)", InDegree ?x (?a + ?b)
-    InDegree ?x ?a                    =>  print "InDegree \(?x) \(?a)"
-    InDegree ?x 0                     =>  print "RULE 3, x=\(?x)", AdjustInDegrees ?x, MList.add answer ?x
-    AdjustInDegrees ?x, Dep ?x ?y     =>  print "RULE 4, x=\(?x), y=\(?y)", InDegree ?y (-1)
+addSet :: IntegerSet -> Integer -> <Proc> ()
+addSet set newElement = ()
+  where
+    include IntegerSet set
+    True => Element newElement
     
-main = topologicalSort [(2,4),(3,7),(7,2),(1,3)]
+printSet :: IntegerSet -> <Proc> ()
+printSet set = ()
+  where
+    include IntegerSet set
+    Element ?x => print "printing \(?x)" 
+
+main = ()
+  where
+    set = createIntegerSet
+    addSet set 1
+    addSet set 2
+    addSet set 1
+    printSet set
 --
-[1, 3, 7, 2, 4]
\ No newline at end of file
+()