1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Generalize the Abstract.Boolean smart constructors.

This commit is contained in:
Rob Rix 2018-10-22 12:45:36 -04:00
parent 9b3fb906ae
commit ee077944ca

View File

@ -114,15 +114,15 @@ newtype FunctionC term address value m a = FunctionC { runFunctionC :: (term ->
-- | Construct a boolean value in the abstract domain. -- | Construct a boolean value in the abstract domain.
boolean :: (Member (Boolean value) sig, Carrier sig m) => Bool -> Evaluator term address value m value boolean :: (Member (Boolean value) sig, Carrier sig m) => Bool -> m value
boolean = send . flip Boolean ret boolean = send . flip Boolean ret
-- | Extract a 'Bool' from a given value. -- | Extract a 'Bool' from a given value.
asBool :: (Member (Boolean value) sig, Carrier sig m) => value -> Evaluator term address value m Bool asBool :: (Member (Boolean value) sig, Carrier sig m) => value -> m Bool
asBool = send . flip AsBool ret asBool = send . flip AsBool ret
-- | Eliminate boolean values. TODO: s/boolean/truthy -- | Eliminate boolean values. TODO: s/boolean/truthy
ifthenelse :: (Member (Boolean value) sig, Carrier sig m) => value -> Evaluator term address value m a -> Evaluator term address value m a -> Evaluator term address value m a ifthenelse :: (Member (Boolean value) sig, Carrier sig m, Monad m) => value -> m a -> m a -> m a
ifthenelse v t e = asBool v >>= \ c -> if c then t else e ifthenelse v t e = asBool v >>= \ c -> if c then t else e
-- | Compute the disjunction (boolean or) of two computed values. This should have short-circuiting semantics where applicable. -- | Compute the disjunction (boolean or) of two computed values. This should have short-circuiting semantics where applicable.