usesOfEA :: UsesOfAcc acc -> Idx aenv a -> PreOpenExp acc env aenv t -> Int
usesOfEA s idx exp =
  case exp of
    Let bnd body        -> usesOfEA s idx bnd + usesOfEA s idx body
    Var _               -> 0
    Const _             -> 0
    Tuple t             -> usesOfTA s idx t
    Prj _ e             -> usesOfEA s idx e
    IndexNil            -> 0
    IndexCons sl sz     -> usesOfEA s idx sl + usesOfEA s idx sz
    IndexHead sh        -> usesOfEA s idx sh
    IndexTail sh        -> usesOfEA s idx sh
    IndexSlice _ ix sh  -> usesOfEA s idx ix + usesOfEA s idx sh
    IndexFull _ ix sl   -> usesOfEA s idx ix + usesOfEA s idx sl
    IndexAny            -> 0
    ToIndex sh ix       -> usesOfEA s idx sh + usesOfEA s idx ix
    FromIndex sh i      -> usesOfEA s idx sh + usesOfEA s idx i
    Cond p t e          -> usesOfEA s idx p  + usesOfEA s idx t  + usesOfEA s idx e
    Iterate n f x       -> usesOfEA s idx n  + usesOfEA s idx f  + usesOfEA s idx x
    PrimConst _         -> 0
    PrimApp _ x         -> usesOfEA s idx x
    Index a sh          -> s idx a + usesOfEA s idx sh
    LinearIndex a i     -> s idx a + usesOfEA s idx i
    Shape a             -> s idx a
    ShapeSize sh        -> usesOfEA s idx sh
    Intersect sh sz     -> usesOfEA s idx sh + usesOfEA s idx sz
usesOfEA :: UsesOfAcc acc -> Idx aenv a -> PreOpenExp acc env aenv t -> Int
usesOfEA s idx exp =
  case exp of
    Let bnd body        -> usesOfEA s idx bnd + usesOfEA s idx body
    Var _               -> 0
    Const _             -> 0
    Tuple t             -> usesOfTA s idx t
    Prj _ e             -> usesOfEA s idx e
    IndexNil            -> 0
    IndexCons sl sz     -> usesOfEA s idx sl + usesOfEA s idx sz
    IndexHead sh        -> usesOfEA s idx sh
    IndexTail sh        -> usesOfEA s idx sh
    IndexSlice _ ix sh  -> usesOfEA s idx ix + usesOfEA s idx sh
    IndexFull _ ix sl   -> usesOfEA s idx ix + usesOfEA s idx sl
    IndexAny            -> 0
    ToIndex sh ix       -> usesOfEA s idx sh + usesOfEA s idx ix
    FromIndex sh i      -> usesOfEA s idx sh + usesOfEA s idx i
    Cond p t e          -> usesOfEA s idx p  + usesOfEA s idx t  + usesOfEA s idx e
    Iterate n f x       -> usesOfEA s idx n  + usesOfEA s idx f  + usesOfEA s idx x
    PrimConst _         -> 0
    PrimApp _ x         -> usesOfEA s idx x
    Index a sh          -> s idx a + usesOfEA s idx sh
    LinearIndex a i     -> s idx a + usesOfEA s idx i
    Shape a             -> s idx a
    ShapeSize sh        -> usesOfEA s idx sh
    Intersect sh sz     -> usesOfEA s idx sh + usesOfEA s idx sz
usesOfEA s idx exp =
  case exp of
    Let bnd body        -> usesOfEA s idx bnd + usesOfEA s idx body
    Var _               -> 0
    Const _             -> 0
    Tuple t             -> usesOfTA s idx t
    Prj _ e             -> usesOfEA s idx e
    IndexNil            -> 0
    IndexCons sl sz     -> usesOfEA s idx sl + usesOfEA s idx sz
    IndexHead sh        -> usesOfEA s idx sh
    IndexTail sh        -> usesOfEA s idx sh
    IndexSlice _ ix sh  -> usesOfEA s idx ix + usesOfEA s idx sh
    IndexFull _ ix sl   -> usesOfEA s idx ix + usesOfEA s idx sl
    IndexAny            -> 0
    ToIndex sh ix       -> usesOfEA s idx sh + usesOfEA s idx ix
    FromIndex sh i      -> usesOfEA s idx sh + usesOfEA s idx i
    Cond p t e          -> usesOfEA s idx p  + usesOfEA s idx t  + usesOfEA s idx e
    Iterate n f x       -> usesOfEA s idx n  + usesOfEA s idx f  + usesOfEA s idx x
    PrimConst _         -> 0
    PrimApp _ x         -> usesOfEA s idx x
    Index a sh          -> s idx a + usesOfEA s idx sh
    LinearIndex a i     -> s idx a + usesOfEA s idx i
    Shape a             -> s idx a
    ShapeSize sh        -> usesOfEA s idx sh
    Intersect sh sz     -> usesOfEA s idx sh + usesOfEA s idx sz