| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Bimatchable
Synopsis
- class (Eq2 t, Bifunctor t) => Bimatchable t where
- bizipMatch :: t a b -> t a' b' -> Maybe (t (a, a') (b, b'))
- bizipMatchWith :: (a -> a' -> Maybe a'') -> (b -> b' -> Maybe b'') -> t a b -> t a' b' -> Maybe (t a'' b'')
- bimapRecovered :: Bimatchable t => (a -> a') -> (b -> b') -> t a b -> t a' b'
- eq2Default :: (Bimatchable t, Eq a, Eq b) => t a b -> t a b -> Bool
- liftEq2Default :: Bimatchable t => (a -> a' -> Bool) -> (b -> b' -> Bool) -> t a b -> t a' b' -> Bool
Documentation
class (Eq2 t, Bifunctor t) => Bimatchable t where Source #
Containers that allows exact structural matching of two containers.
Bimatchable is Bifunctor-version of Matchable.
It can compare and zip containers with two parameters.
Minimal complete definition
Methods
bizipMatch :: t a b -> t a' b' -> Maybe (t (a, a') (b, b')) Source #
bizipMatch is to zipMatch what bimap is to fmap.
Decides if two structures match exactly. If they match, return zipped version of them.
Law
Forall x :: t a b, y :: t a' b', z :: t (a,a') (b,b'),
bizipMatch x y = Just z
holds if and only if both of
x = bimap fst fst z y = bimap snd snd z
holds. Otherwise, bizipMatch x y = Nothing.
Example
>>>bizipMatch (Left 1) (Left 'a')Just (Left (1,'a'))>>>bizipMatch (Right 1) (Right False)Just (Right (1,False))>>>bizipMatch (Left 1) (Right False)Nothing
bizipMatchWith :: (a -> a' -> Maybe a'') -> (b -> b' -> Maybe b'') -> t a b -> t a' b' -> Maybe (t a'' b'') Source #
bizipMatchWith is to zipMatchWith what bimap is to fmap.
Match two structures. If they match, zip them with given functions
(a -> a' -> Maybe a'') and (b -> b -> Maybe b'').
Passed functions can make whole match failby returning Nothing.
Law
For any
x :: t a b y :: t a' b' f :: a -> a' -> Maybe a'' g :: b -> b' -> Maybe b''
bizipMatchWith must satisfy the following.
If there is a pair
(z :: t (a,a') (b,b'), w :: t a'' b'')such that fulfills all of the following three conditions, thenbizipMatchWith f g x y = Just w.x = bimap fst fst z
y = bimap snd snd z
bimap (uncurry f) (uncurry g) z = bimap Just Just w
- If there are no such pair,
bizipMatchWith f g x y = Nothing.
Instances
| Bimatchable Either Source # | |
| Bimatchable (,) Source # | |
Defined in Data.Bimatchable Methods bizipMatch :: (a, b) -> (a', b') -> Maybe ((a, a'), (b, b')) Source # bizipMatchWith :: (a -> a' -> Maybe a'') -> (b -> b' -> Maybe b'') -> (a, b) -> (a', b') -> Maybe (a'', b'') Source # | |
| Bimatchable (Const :: Type -> Type -> Type) Source # | |
| Bimatchable (Tagged :: Type -> Type -> Type) Source # | |
bimapRecovered :: Bimatchable t => (a -> a') -> (b -> b') -> t a b -> t a' b' Source #
eq2Default :: (Bimatchable t, Eq a, Eq b) => t a b -> t a b -> Bool Source #
liftEq2Default :: Bimatchable t => (a -> a' -> Bool) -> (b -> b' -> Bool) -> t a b -> t a' b' -> Bool Source #