{-# LANGUAGE TypeApplications #-}
module Data.Recursive.DualBool (RDualBool, module Data.Recursive.DualBool) where
import Data.Recursive.Internal
import qualified Data.Propagator.Purify as Purify
import Data.Propagator.P2
get :: RDualBool -> Bool
get :: RDualBool -> Bool
get (RDualBool Purify P2
p) = Bool -> Bool
Prelude.not (Purify P2 -> Bool
forall pa a. Propagator pa a => Purify pa -> a
Purify.get Purify P2
p)
mk :: Bool -> RDualBool
mk :: Bool -> RDualBool
mk Bool
b = OpenR RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR RDualBool -> RDualBool) -> OpenR RDualBool -> RDualBool
forall a b. (a -> b) -> a -> b
$ Bool -> Purify P2
forall p a. Propagator p a => a -> Purify p
Purify.mk (Bool -> Bool
Prelude.not Bool
b)
true :: RDualBool
true :: RDualBool
true = OpenR RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR RDualBool -> RDualBool) -> OpenR RDualBool -> RDualBool
forall a b. (a -> b) -> a -> b
$ Bool -> Purify P2
forall p a. Propagator p a => a -> Purify p
Purify.mk Bool
False
false :: RDualBool
false :: RDualBool
false = OpenR RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR RDualBool -> RDualBool) -> OpenR RDualBool -> RDualBool
forall a b. (a -> b) -> a -> b
$ Bool -> Purify P2
forall p a. Propagator p a => a -> Purify p
Purify.mk Bool
True
(&&) :: RDualBool -> RDualBool -> RDualBool
&& :: RDualBool -> RDualBool -> RDualBool
(&&) = OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool -> RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool -> RDualBool -> RDualBool)
-> OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool
-> RDualBool
-> RDualBool
forall a b. (a -> b) -> a -> b
$ (P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2
forall pa a pb b pc c.
(Propagator pa a, Propagator pb b, Propagator pc c) =>
(pa -> pb -> pc -> IO ()) -> Purify pa -> Purify pb -> Purify pc
Purify.def2 ((P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2)
-> (P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2
forall a b. (a -> b) -> a -> b
$ \P2
p1 P2
p2 P2
p -> do
P2 -> IO () -> IO ()
whenTop P2
p1 (P2 -> IO ()
setTop P2
p)
P2 -> IO () -> IO ()
whenTop P2
p2 (P2 -> IO ()
setTop P2
p)
(||) :: RDualBool -> RDualBool -> RDualBool
|| :: RDualBool -> RDualBool -> RDualBool
(||) = OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool -> RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool -> RDualBool -> RDualBool)
-> OpenR (RDualBool -> RDualBool -> RDualBool)
-> RDualBool
-> RDualBool
-> RDualBool
forall a b. (a -> b) -> a -> b
$ (P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2
forall pa a pb b pc c.
(Propagator pa a, Propagator pb b, Propagator pc c) =>
(pa -> pb -> pc -> IO ()) -> Purify pa -> Purify pb -> Purify pc
Purify.def2 ((P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2)
-> (P2 -> P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2 -> Purify P2
forall a b. (a -> b) -> a -> b
$ \P2
p1 P2
p2 P2
p ->
P2 -> IO () -> IO ()
whenTop P2
p1 (P2 -> IO () -> IO ()
whenTop P2
p2 (P2 -> IO ()
setTop P2
p))
and :: [RDualBool] -> RDualBool
and :: [RDualBool] -> RDualBool
and = OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool)
-> OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool
forall a b. (a -> b) -> a -> b
$ ([P2] -> P2 -> IO ()) -> [Purify P2] -> Purify P2
forall pa a pb b.
(Propagator pa a, Propagator pb b) =>
([pa] -> pb -> IO ()) -> [Purify pa] -> Purify pb
Purify.defList (([P2] -> P2 -> IO ()) -> [Purify P2] -> Purify P2)
-> ([P2] -> P2 -> IO ()) -> [Purify P2] -> Purify P2
forall a b. (a -> b) -> a -> b
$ \[P2]
ps P2
p ->
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ @[] (P2 -> P2 -> IO ()
`implies` P2
p) [P2]
ps
or :: [RDualBool] -> RDualBool
or :: [RDualBool] -> RDualBool
or = OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool)
-> OpenR ([RDualBool] -> RDualBool) -> [RDualBool] -> RDualBool
forall a b. (a -> b) -> a -> b
$ ([P2] -> P2 -> IO ()) -> [Purify P2] -> Purify P2
forall pa a pb b.
(Propagator pa a, Propagator pb b) =>
([pa] -> pb -> IO ()) -> [Purify pa] -> Purify pb
Purify.defList [P2] -> P2 -> IO ()
go
where
go :: [P2] -> P2 -> IO ()
go [] P2
p = P2 -> IO ()
setTop P2
p
go (P2
p':[P2]
ps) P2
p = P2 -> IO () -> IO ()
whenTop P2
p' ([P2] -> P2 -> IO ()
go [P2]
ps P2
p)
not :: RBool -> RDualBool
not :: RBool -> RDualBool
not = OpenR (RBool -> RDualBool) -> RBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR (RBool -> RDualBool) -> RBool -> RDualBool)
-> OpenR (RBool -> RDualBool) -> RBool -> RDualBool
forall a b. (a -> b) -> a -> b
$ (P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2
forall pa a pb b.
(Propagator pa a, Propagator pb b) =>
(pa -> pb -> IO ()) -> Purify pa -> Purify pb
Purify.def1 ((P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2)
-> (P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2
forall a b. (a -> b) -> a -> b
$ \P2
p1 P2
p -> do
P2 -> P2 -> IO ()
implies P2
p1 P2
p
id :: RDualBool -> RDualBool
id :: RDualBool -> RDualBool
id = OpenR (RDualBool -> RDualBool) -> RDualBool -> RDualBool
forall a. Coercible a (OpenR a) => OpenR a -> a
openR (OpenR (RDualBool -> RDualBool) -> RDualBool -> RDualBool)
-> OpenR (RDualBool -> RDualBool) -> RDualBool -> RDualBool
forall a b. (a -> b) -> a -> b
$ (P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2
forall pa a pb b.
(Propagator pa a, Propagator pb b) =>
(pa -> pb -> IO ()) -> Purify pa -> Purify pb
Purify.def1 ((P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2)
-> (P2 -> P2 -> IO ()) -> Purify P2 -> Purify P2
forall a b. (a -> b) -> a -> b
$ \P2
p1 P2
p ->
P2 -> P2 -> IO ()
implies P2
p1 P2
p