@@ -75,7 +75,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
75
75
, binary euclideanRingNumber opDiv Divide
76
76
77
77
-- , binary eqNumber opEq EqualTo
78
- , binary eqNumber opNotEq NotEqualTo
78
+ -- , binary eqNumber opNotEq NotEqualTo
79
79
, binary eqInt opEq EqualTo
80
80
, binary eqInt opNotEq NotEqualTo
81
81
, binary eqString opEq EqualTo
@@ -122,7 +122,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
122
122
123
123
, inlineNonClassFunction (isModFn (C. dataFunction, C. apply)) $ \ f x -> App Nothing f [x]
124
124
, 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 )
126
126
] -- ++
127
127
-- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
128
128
-- [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
@@ -186,13 +186,14 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
186
186
runFn :: Int -> AST -> AST
187
187
runFn = runFn' C. dataFunctionUncurried C. runFn (\ ss f args ->
188
188
let len = length args
189
- typ = mkString $ " Fn " <> ( T. pack . show $ len) in
189
+ typ = mkString $ uncurriedFnType len in
190
190
if len > 0
191
191
then App ss (App Nothing (StringLiteral Nothing typ) [f]) args
192
192
else App ss f args)
193
193
runEffFn :: Text -> Text -> Int -> AST -> AST
194
194
runEffFn modName fnName = runFn' modName fnName $ \ ss fn acc ->
195
- Function ss Nothing [] (Block ss [Return ss (App ss fn acc)])
195
+ let typ = mkString . uncurriedFnType $ length acc in
196
+ Function ss Nothing [] (Block ss [Return ss (App ss (App Nothing (StringLiteral Nothing typ) [fn]) acc)])
196
197
197
198
runFn' :: Text -> Text -> (Maybe SourceSpan -> AST -> [AST ] -> AST ) -> Int -> AST -> AST
198
199
runFn' modName runFnName res n = convert where
@@ -211,6 +212,17 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
211
212
convert (App _ (App _ op' [x]) [y]) | p op' = f x y
212
213
convert other = other
213
214
215
+ inlineUnsafeIndex :: (AST -> Bool ) -> (AST -> AST -> AST ) -> AST -> AST
216
+ inlineUnsafeIndex p _ = convert where
217
+ convert :: AST -> AST
218
+ convert (App _ (App ss op' [x]) [y@ NumericLiteral {}])
219
+ | p op' = Indexer ss y x
220
+ convert (App _ (App ss op' [x]) [y])
221
+ | p op' = Indexer ss y' x
222
+ where
223
+ y' = App Nothing (StringLiteral Nothing $ mkString int) [y]
224
+ convert other = other
225
+
214
226
isModFn :: (Text , PSString ) -> AST -> Bool
215
227
isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
216
228
m == m' && decodeString op == Just op'
@@ -294,8 +306,8 @@ ringInt = (C.dataRing, C.ringInt)
294
306
euclideanRingNumber :: forall a b . (IsString a , IsString b ) => (a , b )
295
307
euclideanRingNumber = (C. dataEuclideanRing, C. euclideanRingNumber)
296
308
297
- eqNumber :: forall a b . (IsString a , IsString b ) => (a , b )
298
- eqNumber = (C. dataEq, C. eqNumber)
309
+ -- eqNumber :: forall a b. (IsString a, IsString b) => (a, b)
310
+ -- eqNumber = (C.dataEq, C.eqNumber)
299
311
300
312
eqInt :: forall a b . (IsString a , IsString b ) => (a , b )
301
313
eqInt = (C. dataEq, C. eqInt)
0 commit comments