@@ -23,7 +23,7 @@ import Data.Foldable (fold)
23import qualified Data.Set as S
23import qualified Data.Set as S
25import Control.Monad
25import Control.Monad
26−import Control.Arrow ((***), (+++), second)
26+import Control.Arrow ((***), (+++))
28import Language.PureScript.AST.Binders
28import Language.PureScript.AST.Binders
29import Language.PureScript.AST.Declarations
29import Language.PureScript.AST.Declarations
@@ -49,16 +49,13 @@ everywhereOnValues f g h = (f', g', h')
49 g' :: Expr -> Expr
49 g' :: Expr -> Expr
50 g' (UnaryMinus v) = g (UnaryMinus (g' v))
50 g' (UnaryMinus v) = g (UnaryMinus (g' v))
51 g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
51 g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
52− g' (Parens v) = g (Parens (g' v))
53 g' (OperatorSection op (Left v)) = g (OperatorSection (g' op) (Left $ g' v))
52 g' (OperatorSection op (Left v)) = g (OperatorSection (g' op) (Left $ g' v))
54 g' (OperatorSection op (Right v)) = g (OperatorSection (g' op) (Right $ g' v))
53 g' (OperatorSection op (Right v)) = g (OperatorSection (g' op) (Right $ g' v))
55 g' (ArrayLiteral vs) = g (ArrayLiteral (map g' vs))
54 g' (ArrayLiteral vs) = g (ArrayLiteral (map g' vs))
56 g' (ObjectLiteral vs) = g (ObjectLiteral (map (fmap g') vs))
55 g' (ObjectLiteral vs) = g (ObjectLiteral (map (fmap g') vs))
57− g' (ObjectConstructor vs) = g (ObjectConstructor (map (second (fmap g')) vs))
58 g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
56 g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
59 g' (Accessor prop v) = g (Accessor prop (g' v))
57 g' (Accessor prop v) = g (Accessor prop (g' v))
60 g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
58 g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
61− g' (ObjectUpdater obj vs) = g (ObjectUpdater (fmap g' obj) (map (second (fmap g')) vs))
62 g' (Abs name v) = g (Abs name (g' v))
59 g' (Abs name v) = g (Abs name (g' v))
63 g' (App v1 v2) = g (App (g' v1) (g' v2))
60 g' (App v1 v2) = g (App (g' v1) (g' v2))
64 g' (IfThenElse v1 v2 v3) = g (IfThenElse (g' v1) (g' v2) (g' v3))
61 g' (IfThenElse v1 v2 v3) = g (IfThenElse (g' v1) (g' v2) (g' v3))
@@ -107,16 +104,13 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
108 g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
105 g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
109 g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
106 g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
110− g' (Parens v) = Parens <$> (g v >>= g')
111 g' (OperatorSection op (Left v)) = OperatorSection <$> (g op >>= g') <*> (Left <$> (g v >>= g'))
107 g' (OperatorSection op (Left v)) = OperatorSection <$> (g op >>= g') <*> (Left <$> (g v >>= g'))
112 g' (OperatorSection op (Right v)) = OperatorSection <$> (g op >>= g') <*> (Right <$> (g v >>= g'))
108 g' (OperatorSection op (Right v)) = OperatorSection <$> (g op >>= g') <*> (Right <$> (g v >>= g'))
113 g' (ArrayLiteral vs) = ArrayLiteral <$> traverse (g' <=< g) vs
109 g' (ArrayLiteral vs) = ArrayLiteral <$> traverse (g' <=< g) vs
114 g' (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g' <=< g)) vs
110 g' (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g' <=< g)) vs
115− g' (ObjectConstructor vs) = ObjectConstructor <$> traverse (sndM $ maybeM (g' <=< g)) vs
116 g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
111 g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
117 g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
112 g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
118 g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
113 g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
119− g' (ObjectUpdater obj vs) = ObjectUpdater <$> (maybeM g obj >>= maybeM g') <*> traverse (sndM $ maybeM (g' <=< g)) vs
120 g' (Abs name v) = Abs name <$> (g v >>= g')
114 g' (Abs name v) = Abs name <$> (g v >>= g')
121 g' (App v1 v2) = App <$> (g v1 >>= g') <*> (g v2 >>= g')
115 g' (App v1 v2) = App <$> (g v1 >>= g') <*> (g v2 >>= g')
122 g' (IfThenElse v1 v2 v3) = IfThenElse <$> (g v1 >>= g') <*> (g v2 >>= g') <*> (g v3 >>= g')
116 g' (IfThenElse v1 v2 v3) = IfThenElse <$> (g v1 >>= g') <*> (g v2 >>= g') <*> (g v3 >>= g')
@@ -160,16 +154,13 @@ everywhereOnValuesM f g h = (f', g', h')
161 g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
155 g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
162 g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
156 g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
163− g' (Parens v) = (Parens <$> g' v) >>= g
164 g' (OperatorSection op (Left v)) = (OperatorSection <$> g' op <*> (Left <$> g' v)) >>= g
157 g' (OperatorSection op (Left v)) = (OperatorSection <$> g' op <*> (Left <$> g' v)) >>= g
165 g' (OperatorSection op (Right v)) = (OperatorSection <$> g' op <*> (Right <$> g' v)) >>= g
158 g' (OperatorSection op (Right v)) = (OperatorSection <$> g' op <*> (Right <$> g' v)) >>= g
166 g' (ArrayLiteral vs) = (ArrayLiteral <$> traverse g' vs) >>= g
159 g' (ArrayLiteral vs) = (ArrayLiteral <$> traverse g' vs) >>= g
167 g' (ObjectLiteral vs) = (ObjectLiteral <$> traverse (sndM g') vs) >>= g
160 g' (ObjectLiteral vs) = (ObjectLiteral <$> traverse (sndM g') vs) >>= g
168− g' (ObjectConstructor vs) = (ObjectConstructor <$> traverse (sndM $ maybeM g') vs) >>= g
169 g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
161 g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
170 g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
162 g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
171 g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
163 g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
172− g' (ObjectUpdater obj vs) = (ObjectUpdater <$> maybeM g' obj <*> traverse (sndM $ maybeM g') vs) >>= g
173 g' (Abs name v) = (Abs name <$> g' v) >>= g
164 g' (Abs name v) = (Abs name <$> g' v) >>= g
174 g' (App v1 v2) = (App <$> g' v1 <*> g' v2) >>= g
165 g' (App v1 v2) = (App <$> g' v1 <*> g' v2) >>= g
175 g' (IfThenElse v1 v2 v3) = (IfThenElse <$> g' v1 <*> g' v2 <*> g' v3) >>= g
166 g' (IfThenElse v1 v2 v3) = (IfThenElse <$> g' v1 <*> g' v2 <*> g' v3) >>= g
@@ -216,16 +207,13 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
217 g' v@(UnaryMinus v1) = g v <> g' v1
208 g' v@(UnaryMinus v1) = g v <> g' v1
218 g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
209 g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
219− g' v@(Parens v1) = g v <> g' v1
220 g' v@(OperatorSection op (Left v1)) = g v <> g' op <> g' v1
210 g' v@(OperatorSection op (Left v1)) = g v <> g' op <> g' v1
221 g' v@(OperatorSection op (Right v1)) = g v <> g' op <> g' v1
211 g' v@(OperatorSection op (Right v1)) = g v <> g' op <> g' v1
222 g' v@(ArrayLiteral vs) = foldl (<>) (g v) (map g' vs)
212 g' v@(ArrayLiteral vs) = foldl (<>) (g v) (map g' vs)
223 g' v@(ObjectLiteral vs) = foldl (<>) (g v) (map (g' . snd) vs)
213 g' v@(ObjectLiteral vs) = foldl (<>) (g v) (map (g' . snd) vs)
224− g' v@(ObjectConstructor vs) = foldl (<>) (g v) (map g' (mapMaybe snd vs))
225 g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
214 g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
226 g' v@(Accessor _ v1) = g v <> g' v1
215 g' v@(Accessor _ v1) = g v <> g' v1
227 g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
216 g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
228− g' v@(ObjectUpdater obj vs) = foldl (<>) (maybe (g v) (\x -> g v <> g' x) obj) (map g' (mapMaybe snd vs))
229 g' v@(Abs _ v1) = g v <> g' v1
217 g' v@(Abs _ v1) = g v <> g' v1
230 g' v@(App v1 v2) = g v <> g' v1 <> g' v2
218 g' v@(App v1 v2) = g v <> g' v1 <> g' v2
231 g' v@(IfThenElse v1 v2 v3) = g v <> g' v1 <> g' v2 <> g' v3
219 g' v@(IfThenElse v1 v2 v3) = g v <> g' v1 <> g' v2 <> g' v3
@@ -283,16 +271,13 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
284 g' s (UnaryMinus v1) = g'' s v1
272 g' s (UnaryMinus v1) = g'' s v1
285 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
273 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
286− g' s (Parens v1) = g'' s v1
287 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
274 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
288 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
275 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
289 g' s (ArrayLiteral vs) = foldl (<>) r0 (map (g'' s) vs)
276 g' s (ArrayLiteral vs) = foldl (<>) r0 (map (g'' s) vs)
290 g' s (ObjectLiteral vs) = foldl (<>) r0 (map (g'' s . snd) vs)
277 g' s (ObjectLiteral vs) = foldl (<>) r0 (map (g'' s . snd) vs)
291− g' s (ObjectConstructor vs) = foldl (<>) r0 (map (g'' s) (mapMaybe snd vs))
292 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
278 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
293 g' s (Accessor _ v1) = g'' s v1
279 g' s (Accessor _ v1) = g'' s v1
294 g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
280 g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
295− g' s (ObjectUpdater obj vs) = foldl (<>) (maybe r0 (g'' s) obj) (map (g'' s) (mapMaybe snd vs))
296 g' s (Abs _ v1) = g'' s v1
281 g' s (Abs _ v1) = g'' s v1
297 g' s (App v1 v2) = g'' s v1 <> g'' s v2
282 g' s (App v1 v2) = g'' s v1 <> g'' s v2
298 g' s (IfThenElse v1 v2 v3) = g'' s v1 <> g'' s v2 <> g'' s v3
283 g' s (IfThenElse v1 v2 v3) = g'' s v1 <> g'' s v2 <> g'' s v3
@@ -353,16 +338,13 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
354 g' s (UnaryMinus v) = UnaryMinus <$> g'' s v
339 g' s (UnaryMinus v) = UnaryMinus <$> g'' s v
355 g' s (BinaryNoParens op v1 v2) = BinaryNoParens <$> g'' s op <*> g'' s v1 <*> g'' s v2
340 g' s (BinaryNoParens op v1 v2) = BinaryNoParens <$> g'' s op <*> g'' s v1 <*> g'' s v2
356− g' s (Parens v) = Parens <$> g'' s v
357 g' s (OperatorSection op (Left v)) = OperatorSection <$> g'' s op <*> (Left <$> g'' s v)
341 g' s (OperatorSection op (Left v)) = OperatorSection <$> g'' s op <*> (Left <$> g'' s v)
358 g' s (OperatorSection op (Right v)) = OperatorSection <$> g'' s op <*> (Right <$> g'' s v)
342 g' s (OperatorSection op (Right v)) = OperatorSection <$> g'' s op <*> (Right <$> g'' s v)
359 g' s (ArrayLiteral vs) = ArrayLiteral <$> traverse (g'' s) vs
343 g' s (ArrayLiteral vs) = ArrayLiteral <$> traverse (g'' s) vs
360 g' s (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g'' s)) vs
344 g' s (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g'' s)) vs
361− g' s (ObjectConstructor vs) = ObjectConstructor <$> traverse (sndM $ maybeM (g'' s)) vs
362 g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
345 g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
363 g' s (Accessor prop v) = Accessor prop <$> g'' s v
346 g' s (Accessor prop v) = Accessor prop <$> g'' s v
364 g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
347 g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
365− g' s (ObjectUpdater obj vs) = ObjectUpdater <$> maybeM (g'' s) obj <*> traverse (sndM $ maybeM (g'' s)) vs
366 g' s (Abs name v) = Abs name <$> g'' s v
348 g' s (Abs name v) = Abs name <$> g'' s v
367 g' s (App v1 v2) = App <$> g'' s v1 <*> g'' s v2
349 g' s (App v1 v2) = App <$> g'' s v1 <*> g'' s v2
368 g' s (IfThenElse v1 v2 v3) = IfThenElse <$> g'' s v1 <*> g'' s v2 <*> g'' s v3
350 g' s (IfThenElse v1 v2 v3) = IfThenElse <$> g'' s v1 <*> g'' s v2 <*> g'' s v3
@@ -435,16 +417,13 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
436 g' s (UnaryMinus v1) = g'' s v1
418 g' s (UnaryMinus v1) = g'' s v1
437 g' s (BinaryNoParens op v1 v2) = g' s op <> g' s v1 <> g' s v2
419 g' s (BinaryNoParens op v1 v2) = g' s op <> g' s v1 <> g' s v2
438− g' s (Parens v1) = g'' s v1
439 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
420 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
440 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
421 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
441 g' s (ArrayLiteral vs) = foldMap (g'' s) vs
422 g' s (ArrayLiteral vs) = foldMap (g'' s) vs
442 g' s (ObjectLiteral vs) = foldMap (g'' s . snd) vs
423 g' s (ObjectLiteral vs) = foldMap (g'' s . snd) vs
443− g' s (ObjectConstructor vs) = foldMap (g'' s) (mapMaybe snd vs)
444 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
424 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
445 g' s (Accessor _ v1) = g'' s v1
425 g' s (Accessor _ v1) = g'' s v1
446 g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
426 g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
447− g' s (ObjectUpdater obj vs) = foldMap (g'' s) obj <> foldMap (g'' s) (mapMaybe snd vs)
448 g' s (Abs (Left name) v1) =
427 g' s (Abs (Left name) v1) =
449 let s' = S.insert name s
428 let s' = S.insert name s
450 in g'' s' v1
429 in g'' s' v1