Safe Haskell | None |
---|---|
Language | Haskell98 |
- class (Elt (Tuple pattern), Plain (Unlifted pattern) ~ Tuple pattern) => Unlift pattern where
- unlift :: Unlift pattern => pattern -> Exp (Tuple pattern) -> Unlifted pattern
- modify :: (Lift Exp a, Unlift pattern) => pattern -> (Unlifted pattern -> a) -> Exp (Tuple pattern) -> Exp (Plain a)
- modify2 :: (Lift Exp a, Unlift patternA, Unlift patternB) => patternA -> patternB -> (Unlifted patternA -> Unlifted patternB -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Plain a)
- modify3 :: (Lift Exp a, Unlift patternA, Unlift patternB, Unlift patternC) => patternA -> patternB -> patternC -> (Unlifted patternA -> Unlifted patternB -> Unlifted patternC -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Tuple patternC) -> Exp (Plain a)
- modify4 :: (Lift Exp a, Unlift patternA, Unlift patternB, Unlift patternC, Unlift patternD) => patternA -> patternB -> patternC -> patternD -> (Unlifted patternA -> Unlifted patternB -> Unlifted patternC -> Unlifted patternD -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Tuple patternC) -> Exp (Tuple patternD) -> Exp (Plain a)
- data Exp e = Exp
- expr :: Exp e
- atom :: Exp e
- unliftPair :: (Elt a, Elt b) => Exp (a, b) -> (Exp a, Exp b)
- unliftTriple :: (Elt a, Elt b, Elt c) => Exp (a, b, c) -> (Exp a, Exp b, Exp c)
- unliftQuadruple :: (Elt a, Elt b, Elt c, Elt d) => Exp (a, b, c, d) -> (Exp a, Exp b, Exp c, Exp d)
- asExp :: Exp a -> Exp a
- mapFst :: (Elt a, Elt b, Elt c) => (Exp a -> Exp b) -> Exp (a, c) -> Exp (b, c)
- mapSnd :: (Elt a, Elt b, Elt c) => (Exp b -> Exp c) -> Exp (a, b) -> Exp (a, c)
- fst3 :: (Elt a, Elt b, Elt c) => Exp (a, b, c) -> Exp a
- snd3 :: (Elt a, Elt b, Elt c) => Exp (a, b, c) -> Exp b
- thd3 :: (Elt a, Elt b, Elt c) => Exp (a, b, c) -> Exp c
- indexCons :: Slice ix => Exp ix -> Exp Int -> Exp (ix :. Int)
Documentation
class (Elt (Tuple pattern), Plain (Unlifted pattern) ~ Tuple pattern) => Unlift pattern where Source #
This class simplifies untupling of expressions. If you have a function
g :: ((Exp a, Exp b), Exp (c,d)) -> (Exp e, Exp f)
you cannot apply it to an array arr :: Array sh ((a,b),(c,d))
using map
.
Here, the modify
function helps:
modify ((expr,expr),expr) g :: Exp ((a,b),(c,d)) -> Exp (e,f)
The expr
-pattern tells, how deep the tuple shall be unlifted.
This way you can write:
A.map (Exp.modify ((expr,expr),expr) $ \((a,b), cd) -> g ((a,b), cd)) arr
modify
is based on unlift
.
In contrast to unlift
it does not only unlift one level of tupels,
but is guided by an expr
-pattern.
In the example I have demonstrated,
how the pair (a,b)
is unlifted, but the pair (c,d)
is not.
For the result tuple, modify
simply calls lift
.
In contrast to unlift
,
lift
lifts over all tupel levels until it obtains a single Exp
.
modify :: (Lift Exp a, Unlift pattern) => pattern -> (Unlifted pattern -> a) -> Exp (Tuple pattern) -> Exp (Plain a) Source #
modify2 :: (Lift Exp a, Unlift patternA, Unlift patternB) => patternA -> patternB -> (Unlifted patternA -> Unlifted patternB -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Plain a) Source #
modify3 :: (Lift Exp a, Unlift patternA, Unlift patternB, Unlift patternC) => patternA -> patternB -> patternC -> (Unlifted patternA -> Unlifted patternB -> Unlifted patternC -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Tuple patternC) -> Exp (Plain a) Source #
modify4 :: (Lift Exp a, Unlift patternA, Unlift patternB, Unlift patternC, Unlift patternD) => patternA -> patternB -> patternC -> patternD -> (Unlifted patternA -> Unlifted patternB -> Unlifted patternC -> Unlifted patternD -> a) -> Exp (Tuple patternA) -> Exp (Tuple patternB) -> Exp (Tuple patternC) -> Exp (Tuple patternD) -> Exp (Plain a) Source #