{-# LANGUAGE ExistentialQuantification #-}
module Database.Bolt.Extras.Internal.Condition
(
Condition (..)
, tautology
, matches
, itself
) where
infix 4 :==
infixr 3 :&&
infixr 2 :||
data Condition a = forall b. Eq b => (a -> b) :== b
| Condition a :&& Condition a
| Condition a :|| Condition a
matches :: a -> Condition a -> Bool
matches :: a -> Condition a -> Bool
matches a
obj (a -> b
transform :== b
ref) = a -> b
transform a
obj b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
ref
matches a
obj (Condition a
u :&& Condition a
v) = a -> Condition a -> Bool
forall a. a -> Condition a -> Bool
matches a
obj Condition a
u Bool -> Bool -> Bool
&& a -> Condition a -> Bool
forall a. a -> Condition a -> Bool
matches a
obj Condition a
v
matches a
obj (Condition a
u :|| Condition a
v) = a -> Condition a -> Bool
forall a. a -> Condition a -> Bool
matches a
obj Condition a
u Bool -> Bool -> Bool
|| a -> Condition a -> Bool
forall a. a -> Condition a -> Bool
matches a
obj Condition a
v
tautology :: Condition a
tautology :: Condition a
tautology = Bool -> a -> Bool
forall a b. a -> b -> a
const Bool
True (a -> Bool) -> Bool -> Condition a
forall a b. Eq b => (a -> b) -> b -> Condition a
:== Bool
True
itself :: a -> a
itself :: a -> a
itself = a -> a
forall a. a -> a
id