2 -- | Simple vectorised constructors and projections.
4 Vect, VVar, VExpr, VBind,
13 vVar, vType, vNote, vLet,
14 vLams, vLamsWithoutLC, vVarApps,
18 #include "HsVersions.h"
24 -- | Contains the vectorised and lifted versions of some thing.
27 type VExpr = Vect CoreExpr
28 type VBind = Vect CoreBind
31 -- | Get the vectorised version of a thing.
32 vectorised :: Vect a -> a
36 -- | Get the lifted version of a thing.
41 -- | Apply some function to both the vectorised and lifted versions of a thing.
42 mapVect :: (a -> b) -> Vect a -> Vect b
43 mapVect f (x,y) = (f x, f y)
46 -- | Combine vectorised and lifted versions of two things componentwise.
47 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
48 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
51 -- | Get the type of a vectorised variable.
52 vVarType :: VVar -> Type
53 vVarType = varType . vectorised
56 -- | Wrap a vectorised variable as a vectorised expression.
61 -- | Wrap a vectorised type as a vectorised expression.
62 vType :: Type -> VExpr
63 vType ty = (Type ty, Type ty)
66 -- | Make a vectorised note.
67 vNote :: Note -> VExpr -> VExpr
68 vNote = mapVect . Note
71 -- | Make a vectorised non-recursive binding.
72 vNonRec :: VVar -> VExpr -> VBind
73 vNonRec = zipWithVect NonRec
76 -- | Make a vectorised recursive binding.
77 vRec :: [VVar] -> [VExpr] -> VBind
78 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
84 -- | Make a vectorised let expresion.
85 vLet :: VBind -> VExpr -> VExpr
86 vLet = zipWithVect Let
89 -- | Make a vectorised lambda abstraction.
90 -- The lifted version also binds the lifting context.
91 vLams :: Var -- ^ Var bound to the lifting context.
92 -> [VVar] -- ^ Parameter vars for the abstraction.
93 -> VExpr -- ^ Body of the abstraction.
97 = (mkLams vvs ve, mkLams (lc:lvs) le)
102 -- | Like `vLams` but the lifted version doesn't bind the lifting context.
103 vLamsWithoutLC :: [VVar] -> VExpr -> VExpr
104 vLamsWithoutLC vvs (ve,le)
105 = (mkLams vs ve, mkLams ls le)
110 -- | Apply some argument variables to an expression.
111 -- The lifted version is also applied to the variable of the lifting context.
112 vVarApps :: Var -> VExpr -> [VVar] -> VExpr
113 vVarApps lc (ve, le) vvs
114 = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
120 :: VExpr -- scrutiniy
122 -> Type -- type of vectorised version
123 -> Type -- type of lifted version
124 -> VExpr -- body of alternative.
127 vCaseDEFAULT (vscrut, lscrut) (vbndr, lbndr) vty lty (vbody, lbody)
128 = (Case vscrut vbndr vty (mkDEFAULT vbody),
129 Case lscrut lbndr lty (mkDEFAULT lbody))
131 mkDEFAULT e = [(DEFAULT, [], e)]