module UniqueLogic.ST.TF.Example.Incremental
{-# WARNING "This module is intended for documentation purposes. Do not import it!" #-}
where
import qualified UniqueLogic.ST.TF.Rule as Rule
import qualified UniqueLogic.ST.TF.System.Simple as Sys
import qualified Control.Monad.Trans.Class as MT
import qualified Control.Monad.Trans.State as MS
import Control.Monad.ST (ST, runST, )
example :: [Int]
example =
runST (do
a <- Sys.globalVariable
b <- Sys.globalVariable
c <- Sys.globalVariable
d <- Sys.globalVariable
e <- Sys.globalVariable
f <- Sys.globalVariable
Sys.solve $ do
Rule.equ a c
Rule.equ d f
Rule.equ c e
MS.evalStateT (mapM incQuery [a,b,c,d,e,f]) 0)
incQuery :: Sys.Variable (ST s) Int -> MS.StateT Int (ST s) Int
incQuery v = do
mk <- MT.lift $ Sys.query v
case mk of
Just k -> return k
Nothing -> do
k <- MS.get
MS.put (k+1)
MT.lift $ Sys.solve $ Rule.equ v =<< Sys.constant k
return k