Copyright | (c) Galois Inc 2014-2020 |
---|---|
License | BSD3 |
Maintainer | Langston Barrett <langston@galois.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Often, various operations on values are only partially defined (in the case of
Crucible expressions, consider loading a value from a pointer - this is only
defined in the case that the pointer is valid and non-null). The PartExpr
type allows for packaging values together with predicates that express their
partiality: the value is only valid if the predicate is true.
Synopsis
- data Partial p v = Partial {
- _partialPred :: !p
- _partialValue :: !v
- partialPred :: forall p v p. Lens (Partial p v) (Partial p v) p p
- partialValue :: forall p v v. Lens (Partial p v) (Partial p v) v v
- data PartialWithErr e p v
- type PartExpr p v = PartialWithErr () p v
- pattern PE :: p -> v -> PartExpr p v
- pattern Unassigned :: PartExpr p v
- mkPE :: IsExpr p => p BaseBoolType -> a -> PartExpr (p BaseBoolType) a
- justPartExpr :: IsExprBuilder sym => sym -> v -> PartExpr (Pred sym) v
- maybePartExpr :: IsExprBuilder sym => sym -> Maybe a -> PartExpr (Pred sym) a
- joinMaybePE :: Maybe (PartExpr p v) -> PartExpr p v
- newtype PartialT sym m a = PartialT {}
- runPartialT :: sym -> Pred sym -> PartialT sym m a -> m (PartExpr (Pred sym) a)
- returnUnassigned :: Applicative m => PartialT sym m a
- returnMaybe :: (IsExpr (SymExpr sym), Applicative m) => Maybe a -> PartialT sym m a
- returnPartial :: (IsExprBuilder sym, MonadIO m) => PartExpr (Pred sym) a -> PartialT sym m a
- addCondition :: (IsExprBuilder sym, MonadIO m) => Pred sym -> PartialT sym m ()
- mergePartial :: (IsExprBuilder sym, MonadIO m) => sym -> (Pred sym -> a -> a -> PartialT sym m a) -> Pred sym -> PartExpr (Pred sym) a -> PartExpr (Pred sym) a -> m (PartExpr (Pred sym) a)
- mergePartials :: (IsExprBuilder sym, MonadIO m) => sym -> (Pred sym -> a -> a -> PartialT sym m a) -> [(Pred sym, PartExpr (Pred sym) a)] -> m (PartExpr (Pred sym) a)
Partial
A partial value represents a value that may or may not be valid.
The _partialPred
field represents a predicate (optionally with additional
provenance information) embodying the value's partiality.
Partial | |
|
Instances
Bifoldable Partial Source # | |
Bifunctor Partial Source # | |
Bitraversable Partial Source # | |
Defined in What4.Partial bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Partial a b -> f (Partial c d) # | |
Eq2 Partial Source # | |
Ord2 Partial Source # | |
Defined in What4.Partial | |
Show2 Partial Source # | |
Generic1 (Partial p :: Type -> Type) Source # | |
Foldable (Partial p) Source # | |
Defined in What4.Partial fold :: Monoid m => Partial p m -> m # foldMap :: Monoid m => (a -> m) -> Partial p a -> m # foldMap' :: Monoid m => (a -> m) -> Partial p a -> m # foldr :: (a -> b -> b) -> b -> Partial p a -> b # foldr' :: (a -> b -> b) -> b -> Partial p a -> b # foldl :: (b -> a -> b) -> b -> Partial p a -> b # foldl' :: (b -> a -> b) -> b -> Partial p a -> b # foldr1 :: (a -> a -> a) -> Partial p a -> a # foldl1 :: (a -> a -> a) -> Partial p a -> a # toList :: Partial p a -> [a] # length :: Partial p a -> Int # elem :: Eq a => a -> Partial p a -> Bool # maximum :: Ord a => Partial p a -> a # minimum :: Ord a => Partial p a -> a # | |
Eq p => Eq1 (Partial p) Source # | |
Ord p => Ord1 (Partial p) Source # | |
Defined in What4.Partial | |
Show p => Show1 (Partial p) Source # | |
Traversable (Partial p) Source # | |
Functor (Partial p) Source # | |
(Data p, Data v) => Data (Partial p v) Source # | |
Defined in What4.Partial gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Partial p v -> c (Partial p v) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Partial p v) # toConstr :: Partial p v -> Constr # dataTypeOf :: Partial p v -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Partial p v)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Partial p v)) # gmapT :: (forall b. Data b => b -> b) -> Partial p v -> Partial p v # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Partial p v -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Partial p v -> r # gmapQ :: (forall d. Data d => d -> u) -> Partial p v -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Partial p v -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Partial p v -> m (Partial p v) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Partial p v -> m (Partial p v) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Partial p v -> m (Partial p v) # | |
Generic (Partial p v) Source # | |
(Show p, Show v) => Show (Partial p v) Source # | |
(Eq p, Eq v) => Eq (Partial p v) Source # | |
(Ord p, Ord v) => Ord (Partial p v) Source # | |
Defined in What4.Partial | |
type Rep1 (Partial p :: Type -> Type) Source # | |
Defined in What4.Partial type Rep1 (Partial p :: Type -> Type) = D1 ('MetaData "Partial" "What4.Partial" "what4-1.6.1-FJi93cuUq8WJprgqcgGmcU" 'False) (C1 ('MetaCons "Partial" 'PrefixI 'True) (S1 ('MetaSel ('Just "_partialPred") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 p) :*: S1 ('MetaSel ('Just "_partialValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1)) | |
type Rep (Partial p v) Source # | |
Defined in What4.Partial type Rep (Partial p v) = D1 ('MetaData "Partial" "What4.Partial" "what4-1.6.1-FJi93cuUq8WJprgqcgGmcU" 'False) (C1 ('MetaCons "Partial" 'PrefixI 'True) (S1 ('MetaSel ('Just "_partialPred") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 p) :*: S1 ('MetaSel ('Just "_partialValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 v))) |
PartialWithErr
data PartialWithErr e p v Source #
Either a partial value, or a straight-up error.
Instances
PartExpr
type PartExpr p v = PartialWithErr () p v Source #
A PartExpr
is a PartialWithErr
that provides no information about what
went wrong. Its name is historic.
pattern Unassigned :: PartExpr p v Source #
mkPE :: IsExpr p => p BaseBoolType -> a -> PartExpr (p BaseBoolType) a Source #
justPartExpr :: IsExprBuilder sym => sym -> v -> PartExpr (Pred sym) v Source #
Create a part expression from a value that is always defined.
maybePartExpr :: IsExprBuilder sym => sym -> Maybe a -> PartExpr (Pred sym) a Source #
Create a part expression from a maybe value.
PartialT
newtype PartialT sym m a Source #
A monad transformer which enables symbolic partial computations to run by maintaining a predicate on the value.
Instances
IsExpr (SymExpr sym) => MonadTrans (PartialT sym) Source # | |
Defined in What4.Partial | |
(IsExpr (SymExpr sym), MonadFail m) => MonadFail (PartialT sym m) Source # | |
Defined in What4.Partial | |
(IsExpr (SymExpr sym), MonadIO m) => MonadIO (PartialT sym m) Source # | |
Defined in What4.Partial | |
(IsExpr (SymExpr sym), Monad m) => Applicative (PartialT sym m) Source # | |
Defined in What4.Partial pure :: a -> PartialT sym m a # (<*>) :: PartialT sym m (a -> b) -> PartialT sym m a -> PartialT sym m b # liftA2 :: (a -> b -> c) -> PartialT sym m a -> PartialT sym m b -> PartialT sym m c # (*>) :: PartialT sym m a -> PartialT sym m b -> PartialT sym m b # (<*) :: PartialT sym m a -> PartialT sym m b -> PartialT sym m a # | |
Functor m => Functor (PartialT sym m) Source # | |
(IsExpr (SymExpr sym), Monad m) => Monad (PartialT sym m) Source # | |
:: sym | Solver interface |
-> Pred sym | Initial condition |
-> PartialT sym m a | Computation to run. |
-> m (PartExpr (Pred sym) a) |
Run a partial computation.
returnUnassigned :: Applicative m => PartialT sym m a Source #
End the partial computation and just return the unassigned value.
returnMaybe :: (IsExpr (SymExpr sym), Applicative m) => Maybe a -> PartialT sym m a Source #
Lift a Maybe
value to a partial expression.
returnPartial :: (IsExprBuilder sym, MonadIO m) => PartExpr (Pred sym) a -> PartialT sym m a Source #
Return a partial expression.
This joins the partial expression with the current constraints on the current computation.
addCondition :: (IsExprBuilder sym, MonadIO m) => Pred sym -> PartialT sym m () Source #
Add an extra condition to the current partial computation.
:: (IsExprBuilder sym, MonadIO m) | |
=> sym | |
-> (Pred sym -> a -> a -> PartialT sym m a) | Operation to combine inner values. The |
-> Pred sym | condition to merge on |
-> PartExpr (Pred sym) a | 'if' value |
-> PartExpr (Pred sym) a | 'then' value |
-> m (PartExpr (Pred sym) a) |
If-then-else on partial expressions.
:: (IsExprBuilder sym, MonadIO m) | |
=> sym | |
-> (Pred sym -> a -> a -> PartialT sym m a) | Operation to combine inner values.
The |
-> [(Pred sym, PartExpr (Pred sym) a)] | values to merge |
-> m (PartExpr (Pred sym) a) |
Merge a collection of partial values in an if-then-else tree.
For example, if we merge a list like [(xp,x),(yp,y),(zp,z)]
,
we get a value that is morally equivalent to:
if xp then x else (if yp then y else (if zp then z else undefined))
.