]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/GraphPrelude.scl
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / GraphPrelude.scl
1
2 /**
3  * Databoard
4  */
5 data Binding // Private
6 class Serializable a where
7     getBinding :: Binding
8
9 /**
10  * Reading graph
11  */
12 data Resource
13 data ReadGraph // Private
14 class ReadTransaction where
15     getGraph :: ReadGraph
16
17 resource :: ReadTransaction => String -> Resource
18 (#) :: ReadTransaction => Resource -> Resource -> [Resource]
19 valueOf :: ReadTransaction => Serializable a => Resource -> a
20
21 /**
22  * Writing graph
23  */
24 data WriteGraph // Private
25 data Graph a = Graph (WriteGraph -> a)
26
27 instance Monad Graph where
28     return x = Graph (\_ -> x)
29     Graph g >>= f = \wg -> f (g wg) wg
30     map f (Graph g) = Graph (f . g)
31
32 newResource :: Graph Resource
33 newResource = Graph __WriteGraph_newResource
34 newLiteral :: Serializable a => a -> Graph Resource
35 newLiteral = Graph (\wg -> 
36     literal = __WriteGraph_newResource wg
37     _ = __WriteGraph_claimValue wg literal a getBinding
38     literal 
39 )
40 statement :: Resource -> Resource -> Resource -> Graph ()
41 statement s p o = Graph (\wg -> __WriteGraph_claim wg s p o)