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%2FCHR2.scl;h=05a2e7bb7b05f63a602efac4621b3b895eecfac4;hp=35fb7240abc529283752254b63dac24ac3479003;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR2.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR2.scl index 35fb7240a..05a2e7bb7 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR2.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR2.scl @@ -1,49 +1,49 @@ -import "Prelude" - -gSum :: Additive a => [a] -> a -gSum list = getRef answer - where - answer = ref zero - - constraint El a - - ?x <- list => El ?x - -El ?x, -El ?y => El (?x + ?y) - El ?x => answer := ?x - -main = (gSum [1,6,9], gSum [1.0,6.0,9.0]) --- -(16,16.0) --- -import "StandardLibrary" - -topologicalSort :: [(a,a)] -> [a] -topologicalSort dependencies = MList.freeze answer - where - answer = MList.create () - - (?x,?y) <- dependencies => Dep ?x ?y, InDegree ?x 0, InDegree ?y 1 - -InDegree ?x ?a, -InDegree ?x ?b => InDegree ?x (?a + ?b) - InDegree ?x 0 => AdjustInDegrees ?x, MList.add answer ?x - AdjustInDegrees ?x, Dep ?x ?y => InDegree ?y (-1) - -main = topologicalSort [(2,4),(3,7),(7,2),(1,3)] --- -[1, 3, 7, 2, 4] --- -import "StandardLibrary" - -topologicalSort :: Show a => [(a,a)] -> [a] -topologicalSort dependencies = MList.freeze answer - where - answer = MList.create () - - -Candidate ?x, Candidate ?x => True - (?x,?y) <- dependencies => Dep ?x ?y, Candidate ?x - -Candidate ?x, Dep _ ?x => True - Candidate ?x => MList.add answer ?x - Candidate ?x, -Dep ?x ?y => Candidate ?y - -main = topologicalSort [(2,4),(3,7),(7,2),(1,3)] --- -[1, 3, 7, 2, 4] +import "Prelude" + +gSum :: Additive a => [a] -> a +gSum list = getRef answer + where + answer = ref zero + + constraint El a + + ?x <- list => El ?x + -El ?x, -El ?y => El (?x + ?y) + El ?x => answer := ?x + +main = (gSum [1,6,9], gSum [1.0,6.0,9.0]) +-- +(16,16.0) +-- +import "StandardLibrary" + +topologicalSort :: [(a,a)] -> [a] +topologicalSort dependencies = MList.freeze answer + where + answer = MList.create () + + (?x,?y) <- dependencies => Dep ?x ?y, InDegree ?x 0, InDegree ?y 1 + -InDegree ?x ?a, -InDegree ?x ?b => InDegree ?x (?a + ?b) + InDegree ?x 0 => AdjustInDegrees ?x, MList.add answer ?x + AdjustInDegrees ?x, Dep ?x ?y => InDegree ?y (-1) + +main = topologicalSort [(2,4),(3,7),(7,2),(1,3)] +-- +[1, 3, 7, 2, 4] +-- +import "StandardLibrary" + +topologicalSort :: Show a => [(a,a)] -> [a] +topologicalSort dependencies = MList.freeze answer + where + answer = MList.create () + + -Candidate ?x, Candidate ?x => True + (?x,?y) <- dependencies => Dep ?x ?y, Candidate ?x + -Candidate ?x, Dep _ ?x => True + Candidate ?x => MList.add answer ?x + Candidate ?x, -Dep ?x ?y => Candidate ?y + +main = topologicalSort [(2,4),(3,7),(7,2),(1,3)] +-- +[1, 3, 7, 2, 4]