X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FGraphPrelude.scl;fp=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FGraphPrelude.scl;h=ddb2d58befb710ac72b5bc3df60b3701db6ac1a7;hb=0364f8f54b009e9e5de482d5c9d1cb7efb023141;hp=0000000000000000000000000000000000000000;hpb=7ecf07ff9aacab300f1fb900f1f0f97beb1be139;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/GraphPrelude.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/GraphPrelude.scl new file mode 100644 index 000000000..ddb2d58be --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/GraphPrelude.scl @@ -0,0 +1,41 @@ + +/** + * Databoard + */ +data Binding // Private +class Serializable a where + getBinding :: Binding + +/** + * Reading graph + */ +data Resource +data ReadGraph // Private +class ReadTransaction where + getGraph :: ReadGraph + +resource :: ReadTransaction => String -> Resource +(#) :: ReadTransaction => Resource -> Resource -> [Resource] +valueOf :: ReadTransaction => Serializable a => Resource -> a + +/** + * Writing graph + */ +data WriteGraph // Private +data Graph a = Graph (WriteGraph -> a) + +instance Monad Graph where + return x = Graph (\_ -> x) + Graph g >>= f = \wg -> f (g wg) wg + map f (Graph g) = Graph (f . g) + +newResource :: Graph Resource +newResource = Graph __WriteGraph_newResource +newLiteral :: Serializable a => a -> Graph Resource +newLiteral = Graph (\wg -> + literal = __WriteGraph_newResource wg + _ = __WriteGraph_claimValue wg literal a getBinding + literal +) +statement :: Resource -> Resource -> Resource -> Graph () +statement s p o = Graph (\wg -> __WriteGraph_claim wg s p o) \ No newline at end of file