definition:
|
flattenExpr :: Flattening (AExpr a)
flattenExpr xs v@(AVar _ _) = (xs, v)
flattenExpr xs l@(ALit _ _) = (xs, l)
flattenExpr xs (AComb a ct qn es) = let (xs1, ds, es') = splitArgs xs es
in (xs1, flatLet ds (AComb a ct qn es'))
flattenExpr xs (AFree a vs e) = let (xs1, e') = flattenExpr xs e
in (xs1, AFree a vs e')
flattenExpr xs (ALet _ ds e)
= let (xs1, ds') = mapAccumL flatD xs ds -- type argument of ALet?
(xs2, e') = flattenExpr xs1 e
in (xs2, flatLet ds' e')
where
flatD ys (v, ve) = let (ys1, ve') = flattenExpr ys ve
in (ys1, (v, ve'))
flattenExpr xs (AOr a e1 e2) = let (xs1, e1') = flattenExpr xs e1
(xs2, e2') = flattenExpr xs1 e2
in (xs2, AOr a e1' e2')
flattenExpr xs (ACase a ct e bs)
= let (xs1, e') = flattenExpr xs e
(xs2, bs') = mapAccumL flatB xs1 bs
ea = annExpr e
(x : xs3) = xs2
in case e of
AVar _ _ -> (xs2, ACase a ct e' bs')
_ -> (xs3, flatLet [((x, ea), e)] (ACase a ct (AVar ea x) bs'))
where
flatB ys (ABranch p be) = let (ys1, be') = flattenExpr ys be
in (ys1, ABranch p be')
flattenExpr xs (ATyped a e ty) = let (xs1, e') = flattenExpr xs e
in (xs1, ATyped a e' ty)
|
iotype:
|
{(_,{AVar}) |-> {(,)} || (_,{ALit}) |-> {(,)} || (_,{AComb}) |-> {(,)} || (_,{AFree}) |-> {(,)} || (_,{ALet}) |-> {(,)} || (_,{AOr}) |-> {(,)} || (_,{ACase}) |-> _ || (_,{ATyped}) |-> {(,)}}
|