-
Notifications
You must be signed in to change notification settings - Fork 3
/
SatImplicit.hs
executable file
·57 lines (44 loc) · 2.09 KB
/
SatImplicit.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE Rank2Types #-}
module SatImplicit
-- a general implicit interface
( withNewSolver -- :: MonadSat m => (forall s . (?solver :: Solver m s) => m a) -> m a
, runWithSolver -- :: (forall s t . (?solver :: Solver (Sat t) s) => Sat t a) -> a
, newLit -- :: (MonadSat m, ?solver :: Solver m s) => m (Lit s)
, addClause -- :: (MonadSat m, ?solver :: Solver m s) => [Lit s] -> m Bool
, simplify -- :: (MonadSat m, ?solver :: Solver m s) => m ()
, solve -- :: (MonadSat m, ?solver :: Solver m s) => [Lit s] -> m Bool
, value -- :: (MonadSat m, ?solver :: Solver m s) => Lit s -> m (Maybe Bool)
, modelValue -- :: (MonadSat m, ?solver :: Solver m s) => Lit s -> m (Maybe Bool)
, conflict -- :: (MonadSat m, ?solver :: Solver m s) => m [Lit s]
)
where
import qualified Sat as S
import Sat
( Solver
, Lit
, Sat
, MonadSat
)
----------------------------------------------------------------------------
-- using implicit arguments
withNewSolver :: MonadSat m => (forall s . (?solver :: Solver m s) => m a) -> m a
withNewSolver m = S.withNewSolver (\s -> let ?solver = s in m)
runWithSolver :: (forall s t . (?solver :: Solver (Sat t) s) => Sat t a) -> a
runWithSolver m = S.run (S.withNewSolver (\s -> let ?solver = s in m))
newLit :: (MonadSat m, ?solver :: Solver m s) => m (Lit s)
newLit = S.newLit ?solver
addClause :: (MonadSat m, ?solver :: Solver m s) => [Lit s] -> m Bool
addClause xs = S.addClause ?solver xs
simplify :: (MonadSat m, ?solver :: Solver m s) => m ()
simplify = S.simplify ?solver
solve :: (MonadSat m, ?solver :: Solver m s) => [Lit s] -> m Bool
solve xs = S.solve ?solver xs
value :: (MonadSat m, ?solver :: Solver m s) => Lit s -> m (Maybe Bool)
value x = S.value ?solver x
modelValue :: (MonadSat m, ?solver :: Solver m s) => Lit s -> m (Maybe Bool)
modelValue x = S.modelValue ?solver x
conflict :: (MonadSat m, ?solver :: Solver m s) => m [Lit s]
conflict = S.conflict ?solver
----------------------------------------------------------------------------