X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FCHR5.scl;h=00ca32bec06f5b887afd13e5b3a7d1800a939ead;hp=e3c8b8c27d5292acec9abaadaa0fe45336ed8d2b;hb=78f577368ba4c71ad6fb3d9f16c03c634585cf7b;hpb=a2df536f7fc878982c6c960a79ed49f350cddc6f diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl index e3c8b8c27..00ca32bec 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR5.scl @@ -1,16 +1,34 @@ +module { + export = [main], + chr +} + import "StandardLibrary" -topologicalSort :: Show a => [(a,a)] -> [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 -> () +addSet set newElement = () + where + include IntegerSet set + True => Element newElement -main = topologicalSort [(2,4),(3,7),(7,2),(1,3)] +printSet :: IntegerSet -> () +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 +()