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]