toVariantMaybe :: ( a :<? xs ) => a -> Maybe (V xs)
which is in a sense dual to the VMaybe pattern synonym.
I've been writing a program which has an extensible "action" variant type, and want to write actions to a TQueue when the action can be handled. Something like:
signalAction
:: forall action actions
. ( action :<? actions )
=> TQueue (V actions) -> action -> IO ()
signalAction tqueue action = case toVariantMaybe @_ @actions action of
Just a -> atomically ( writeTQueue tqueue a )
Nothing -> pure ()
The constraints in the ToVariantMaybe instances are a subset of the corresponding constraints in the PopVariant instances, so the change in the definition of (:<?) shouldn't have any effect on type-level computations.
This PR adds
which is in a sense dual to the
VMaybe
pattern synonym.I've been writing a program which has an extensible "action" variant type, and want to write actions to a
TQueue
when the action can be handled. Something like:The constraints in the
ToVariantMaybe
instances are a subset of the corresponding constraints in thePopVariant
instances, so the change in the definition of(:<?)
shouldn't have any effect on type-level computations.