2 -- | Simple vectorised constructors and projections.
3 module Vectorise.Vect (
4 Vect, VVar, VExpr, VBind,
26 -- | Contains the vectorised and lifted versions of some thing.
29 type VExpr = Vect CoreExpr
30 type VBind = Vect CoreBind
33 -- | Get the vectorised version of a thing.
34 vectorised :: Vect a -> a
38 -- | Get the lifted version of a thing.
43 -- | Apply some function to both the vectorised and lifted versions of a thing.
44 mapVect :: (a -> b) -> Vect a -> Vect b
45 mapVect f (x,y) = (f x, f y)
48 -- | Combine vectorised and lifted versions of two things componentwise.
49 zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
50 zipWithVect f (x1,y1) (x2,y2) = (f x1 x2, f y1 y2)
53 -- | Get the type of a vectorised variable.
54 vVarType :: VVar -> Type
55 vVarType = varType . vectorised
58 -- | Wrap a vectorised variable as a vectorised expression.
63 -- | Wrap a vectorised type as a vectorised expression.
64 vType :: Type -> VExpr
65 vType ty = (Type ty, Type ty)
68 -- | Make a vectorised note.
69 vNote :: Note -> VExpr -> VExpr
70 vNote = mapVect . Note
73 -- | Make a vectorised non-recursive binding.
74 vNonRec :: VVar -> VExpr -> VBind
75 vNonRec = zipWithVect NonRec
78 -- | Make a vectorised recursive binding.
79 vRec :: [VVar] -> [VExpr] -> VBind
80 vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
86 -- | Make a vectorised let expresion.
87 vLet :: VBind -> VExpr -> VExpr
88 vLet = zipWithVect Let
91 -- | Make a vectorised lambda abstraction.
92 -- The lifted version also binds the lifting context.
93 vLams :: Var -- ^ Var bound to the lifting context.
94 -> [VVar] -- ^ Parameter vars for the abstraction.
95 -> VExpr -- ^ Body of the abstraction.
99 = (mkLams vvs ve, mkLams (lc:lvs) le)
104 -- | Like `vLams` but the lifted version doesn't bind the lifting context.
105 vLamsWithoutLC :: [VVar] -> VExpr -> VExpr
106 vLamsWithoutLC vvs (ve,le)
107 = (mkLams vs ve, mkLams ls le)
112 -- | Apply some argument variables to an expression.
113 -- The lifted version is also applied to the variable of the lifting context.
114 vVarApps :: Var -> VExpr -> [VVar] -> VExpr
115 vVarApps lc (ve, le) vvs
116 = (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
122 :: VExpr -- scrutiniy
124 -> Type -- type of vectorised version
125 -> Type -- type of lifted version
126 -> VExpr -- body of alternative.
129 vCaseDEFAULT (vscrut, lscrut) (vbndr, lbndr) vty lty (vbody, lbody)
130 = (Case vscrut vbndr vty (mkDEFAULT vbody),
131 Case lscrut lbndr lty (mkDEFAULT lbody))
133 mkDEFAULT e = [(DEFAULT, [], e)]