module Internal.Rpc.Breaker
( Client (..),
Pipeline (..),
nullClient,
Opaque,
makeOpaque,
reflectOpaque,
)
where
import Data.Dynamic (Dynamic, Typeable, fromDynamic, toDyn)
newtype Client = Client Opaque
deriving (Client -> Client -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Client -> Client -> Bool
$c/= :: Client -> Client -> Bool
== :: Client -> Client -> Bool
$c== :: Client -> Client -> Bool
Eq)
instance Show Client where
show :: Client -> String
show Client
client =
if Client
client forall a. Eq a => a -> a -> Bool
== Client
nullClient
then String
"nullClient"
else String
"({- capability; not statically representable -})"
newtype Pipeline = Pipeline Opaque
nullClient :: Client
nullClient :: Client
nullClient = Opaque -> Client
Client forall a b. (a -> b) -> a -> b
$ forall a. (Typeable a, Eq a) => a -> Opaque
makeOpaque ()
data Opaque = Opaque
{ Opaque -> Dynamic
opDyn :: Dynamic,
Opaque -> Opaque -> Bool
opEq :: Opaque -> Bool
}
makeOpaque :: (Typeable a, Eq a) => a -> Opaque
makeOpaque :: forall a. (Typeable a, Eq a) => a -> Opaque
makeOpaque a
v =
Opaque
{ opDyn :: Dynamic
opDyn = forall a. Typeable a => a -> Dynamic
toDyn a
v,
opEq :: Opaque -> Bool
opEq = \Opaque
o -> forall a. Typeable a => Dynamic -> Maybe a
fromDynamic (Opaque -> Dynamic
opDyn Opaque
o) forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just a
v
}
reflectOpaque :: Opaque -> Dynamic
reflectOpaque :: Opaque -> Dynamic
reflectOpaque = Opaque -> Dynamic
opDyn
instance Eq Opaque where
Opaque
x == :: Opaque -> Opaque -> Bool
== Opaque
y = Opaque -> Opaque -> Bool
opEq Opaque
x Opaque
y