@@ -122,7 +122,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
122122
123123 , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> App Nothing f [x]
124124 , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> App Nothing f [x]
125− , inlineNonClassFunction (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
125+ , inlineUnsafeIndex (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
126126 ] ++
127127 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
128128 [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
@@ -211,6 +211,15 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
211211 convert (App _ (App _ op' [x]) [y]) | p op' = f x y
212212 convert other = other
213213
214+ inlineUnsafeIndex :: (AST -> Bool) -> (AST -> AST -> AST) -> AST -> AST
215+ inlineUnsafeIndex p _ = convert where
216+ convert :: AST -> AST
217+ convert (App _ (App ss op' [x]) [y@NumericLiteral{}])
218+ | p op' = Indexer ss y x
219+ convert (App _ (App ss op' [x]) [y])
220+ | p op' = App ss (Var Nothing indexFn) [x, y]
221+ convert other = other
222+
214223 isModFn :: (Text, PSString) -> AST -> Bool
215224 isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
216225 m == m' && decodeString op == Just op'