@@ -1,17 +1,8 @@
1−-----------------------------------------------------------------------------
1+{-# LANGUAGE ScopedTypeVariables #-}
3−-- Module : Language.PureScript.AST.Traversals
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
11−-- | AST traversal helpers
13−-----------------------------------------------------------------------------
4+-- AST traversal helpers
15module Language.PureScript.AST.Traversals where
6module Language.PureScript.AST.Traversals where
17import Prelude ()
8import Prelude ()
@@ -26,15 +17,20 @@ import Control.Monad
26import Control.Arrow ((***), (+++))
17import Control.Arrow ((***), (+++))
28import Language.PureScript.AST.Binders
19import Language.PureScript.AST.Binders
20+import Language.PureScript.AST.Literals
29import Language.PureScript.AST.Declarations
21import Language.PureScript.AST.Declarations
30import Language.PureScript.Types
22import Language.PureScript.Types
31import Language.PureScript.Traversals
23import Language.PureScript.Traversals
32import Language.PureScript.Names
24import Language.PureScript.Names
34−everywhereOnValues :: (Declaration -> Declaration) ->
27+ :: (Declaration -> Declaration)
35− (Expr -> Expr) ->
28+ -> (Expr -> Expr)
36− (Binder -> Binder) ->
29+ -> (Binder -> Binder)
37− (Declaration -> Declaration, Expr -> Expr, Binder -> Binder)
30+ -> ( Declaration -> Declaration
38everywhereOnValues f g h = (f', g', h')
34everywhereOnValues f g h = (f', g', h')
40 f' :: Declaration -> Declaration
36 f' :: Declaration -> Declaration
@@ -47,13 +43,12 @@ everywhereOnValues f g h = (f', g', h')
47 f' other = f other
43 f' other = f other
49 g' :: Expr -> Expr
45 g' :: Expr -> Expr
46+ g' (Literal l) = g (Literal (lit g' l))
50 g' (UnaryMinus v) = g (UnaryMinus (g' v))
47 g' (UnaryMinus v) = g (UnaryMinus (g' v))
51 g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
48 g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
52 g' (Parens v) = g (Parens (g' v))
49 g' (Parens v) = g (Parens (g' v))
53 g' (OperatorSection op (Left v)) = g (OperatorSection (g' op) (Left $ g' v))
50 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))
51 g' (OperatorSection op (Right v)) = g (OperatorSection (g' op) (Right $ g' v))
55− g' (ArrayLiteral vs) = g (ArrayLiteral (map g' vs))
56− g' (ObjectLiteral vs) = g (ObjectLiteral (map (fmap g') vs))
57 g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
52 g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
58 g' (Accessor prop v) = g (Accessor prop (g' v))
53 g' (Accessor prop v) = g (Accessor prop (g' v))
59 g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
54 g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
@@ -71,13 +66,17 @@ everywhereOnValues f g h = (f', g', h')
71 h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
66 h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
72 h' (BinaryNoParensBinder b1 b2 b3) = h (BinaryNoParensBinder (h' b1) (h' b2) (h' b3))
67 h' (BinaryNoParensBinder b1 b2 b3) = h (BinaryNoParensBinder (h' b1) (h' b2) (h' b3))
73 h' (ParensInBinder b) = h (ParensInBinder (h' b))
68 h' (ParensInBinder b) = h (ParensInBinder (h' b))
74− h' (ObjectBinder bs) = h (ObjectBinder (map (fmap h') bs))
69+ h' (LiteralBinder l) = h (LiteralBinder (lit h' l))
75− h' (ArrayBinder bs) = h (ArrayBinder (map h' bs))
76 h' (NamedBinder name b) = h (NamedBinder name (h' b))
70 h' (NamedBinder name b) = h (NamedBinder name (h' b))
77 h' (PositionedBinder pos com b) = h (PositionedBinder pos com (h' b))
71 h' (PositionedBinder pos com b) = h (PositionedBinder pos com (h' b))
78 h' (TypedBinder t b) = h (TypedBinder t (h' b))
72 h' (TypedBinder t b) = h (TypedBinder t (h' b))
79 h' other = h other
73 h' other = h other
75+ lit :: (a -> a) -> Literal a -> Literal a
76+ lit go (ArrayLiteral as) = ArrayLiteral (map go as)
77+ lit go (ObjectLiteral as) = ObjectLiteral (map (fmap go) as)
81 handleCaseAlternative :: CaseAlternative -> CaseAlternative
80 handleCaseAlternative :: CaseAlternative -> CaseAlternative
82 handleCaseAlternative ca =
81 handleCaseAlternative ca =
83 ca { caseAlternativeBinders = map h' (caseAlternativeBinders ca)
82 ca { caseAlternativeBinders = map h' (caseAlternativeBinders ca)
@@ -90,13 +89,20 @@ everywhereOnValues f g h = (f', g', h')
90 handleDoNotationElement (DoNotationLet ds) = DoNotationLet (map f' ds)
89 handleDoNotationElement (DoNotationLet ds) = DoNotationLet (map f' ds)
91 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com (handleDoNotationElement e)
90 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com (handleDoNotationElement e)
93−everywhereOnValuesTopDownM :: (Functor m, Applicative m, Monad m) =>
92+everywhereOnValuesTopDownM
94+ . (Functor m, Applicative m, Monad m)
94− (Declaration -> m Declaration) ->
95+ => (Declaration -> m Declaration)
95− (Expr -> m Expr) ->
96+ -> (Expr -> m Expr)
96− (Binder -> m Binder) ->
97+ -> (Binder -> m Binder)
97− (Declaration -> m Declaration, Expr -> m Expr, Binder -> m Binder)
98+ -> ( Declaration -> m Declaration
100+ , Binder -> m Binder
98everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
102everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
105+ f' :: Declaration -> m Declaration
100 f' (DataBindingGroupDeclaration ds) = DataBindingGroupDeclaration <$> traverse (f' <=< f) ds
106 f' (DataBindingGroupDeclaration ds) = DataBindingGroupDeclaration <$> traverse (f' <=< f) ds
101 f' (ValueDeclaration name nameKind bs val) = ValueDeclaration name nameKind <$> traverse (h' <=< h) bs <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
107 f' (ValueDeclaration name nameKind bs val) = ValueDeclaration name nameKind <$> traverse (h' <=< h) bs <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
102 f' (BindingGroupDeclaration ds) = BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> (g val >>= g')) ds
108 f' (BindingGroupDeclaration ds) = BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> (g val >>= g')) ds
@@ -105,13 +111,13 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
105 f' (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> (f d >>= f')
111 f' (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> (f d >>= f')
106 f' other = f other
112 f' other = f other
114+ g' :: Expr -> m Expr
115+ g' (Literal l) = Literal <$> lit (g >=> g') l
108 g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
116 g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
109 g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
117 g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
110 g' (Parens v) = Parens <$> (g v >>= g')
118 g' (Parens v) = Parens <$> (g v >>= g')
111 g' (OperatorSection op (Left v)) = OperatorSection <$> (g op >>= g') <*> (Left <$> (g v >>= g'))
119 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'))
120 g' (OperatorSection op (Right v)) = OperatorSection <$> (g op >>= g') <*> (Right <$> (g v >>= g'))
113− g' (ArrayLiteral vs) = ArrayLiteral <$> traverse (g' <=< g) vs
114− g' (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g' <=< g)) vs
115 g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
121 g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
116 g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
122 g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
117 g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
123 g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
@@ -125,31 +131,47 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
125 g' (PositionedValue pos com v) = PositionedValue pos com <$> (g v >>= g')
131 g' (PositionedValue pos com v) = PositionedValue pos com <$> (g v >>= g')
126 g' other = g other
132 g' other = g other
134+ h' :: Binder -> m Binder
135+ h' (LiteralBinder l) = LiteralBinder <$> lit (h >=> h') l
128 h' (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h' <=< h) bs
136 h' (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h' <=< h) bs
129 h' (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> (h b1 >>= h') <*> (h b2 >>= h') <*> (h b3 >>= h')
137 h' (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> (h b1 >>= h') <*> (h b2 >>= h') <*> (h b3 >>= h')
130 h' (ParensInBinder b) = ParensInBinder <$> (h b >>= h')
138 h' (ParensInBinder b) = ParensInBinder <$> (h b >>= h')
131− h' (ObjectBinder bs) = ObjectBinder <$> traverse (sndM (h' <=< h)) bs
132− h' (ArrayBinder bs) = ArrayBinder <$> traverse (h' <=< h) bs
133 h' (NamedBinder name b) = NamedBinder name <$> (h b >>= h')
139 h' (NamedBinder name b) = NamedBinder name <$> (h b >>= h')
134 h' (PositionedBinder pos com b) = PositionedBinder pos com <$> (h b >>= h')
140 h' (PositionedBinder pos com b) = PositionedBinder pos com <$> (h b >>= h')
135 h' (TypedBinder t b) = TypedBinder t <$> (h b >>= h')
141 h' (TypedBinder t b) = TypedBinder t <$> (h b >>= h')
136 h' other = h other
142 h' other = h other
144+ lit :: (a -> m a) -> Literal a -> m (Literal a)
145+ lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
146+ lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
147+ lit _ other = pure other
149+ handleCaseAlternative :: CaseAlternative -> m CaseAlternative
138− handleCaseAlternative (CaseAlternative bs val) = CaseAlternative <$> traverse (h' <=< h) bs
150+ handleCaseAlternative (CaseAlternative bs val) =
152+ <$> traverse (h' <=< h) bs
139− <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
153+ <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
155+ handleDoNotationElement :: DoNotationElement -> m DoNotationElement
141 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> (g' <=< g) v
156 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> (g' <=< g) v
142 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> (h' <=< h) b <*> (g' <=< g) v
157 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> (h' <=< h) b <*> (g' <=< g) v
143 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse (f' <=< f) ds
158 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse (f' <=< f) ds
144 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
159 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
146−everywhereOnValuesM :: (Functor m, Applicative m, Monad m) =>
163+ . (Functor m, Applicative m, Monad m)
147− (Declaration -> m Declaration) ->
164+ => (Declaration -> m Declaration)
148− (Expr -> m Expr) ->
165+ -> (Expr -> m Expr)
149− (Binder -> m Binder) ->
166+ -> (Binder -> m Binder)
150− (Declaration -> m Declaration, Expr -> m Expr, Binder -> m Binder)
167+ -> ( Declaration -> m Declaration
169+ , Binder -> m Binder
151everywhereOnValuesM f g h = (f', g', h')
171everywhereOnValuesM f g h = (f', g', h')
174+ f' :: Declaration -> m Declaration
153 f' (DataBindingGroupDeclaration ds) = (DataBindingGroupDeclaration <$> traverse f' ds) >>= f
175 f' (DataBindingGroupDeclaration ds) = (DataBindingGroupDeclaration <$> traverse f' ds) >>= f
154 f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$> traverse h' bs <*> eitherM (traverse (pairM g' g')) g' val) >>= f
176 f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$> traverse h' bs <*> eitherM (traverse (pairM g' g')) g' val) >>= f
155 f' (BindingGroupDeclaration ds) = (BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> g' val) ds) >>= f
177 f' (BindingGroupDeclaration ds) = (BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> g' val) ds) >>= f
@@ -158,13 +180,13 @@ everywhereOnValuesM f g h = (f', g', h')
158 f' (PositionedDeclaration pos com d) = (PositionedDeclaration pos com <$> f' d) >>= f
180 f' (PositionedDeclaration pos com d) = (PositionedDeclaration pos com <$> f' d) >>= f
159 f' other = f other
181 f' other = f other
183+ g' :: Expr -> m Expr
184+ g' (Literal l) = (Literal <$> lit g' l) >>= g
161 g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
185 g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
162 g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
186 g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
163 g' (Parens v) = (Parens <$> g' v) >>= g
187 g' (Parens v) = (Parens <$> g' v) >>= g
164 g' (OperatorSection op (Left v)) = (OperatorSection <$> g' op <*> (Left <$> g' v)) >>= g
188 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
189 g' (OperatorSection op (Right v)) = (OperatorSection <$> g' op <*> (Right <$> g' v)) >>= g
166− g' (ArrayLiteral vs) = (ArrayLiteral <$> traverse g' vs) >>= g
167− g' (ObjectLiteral vs) = (ObjectLiteral <$> traverse (sndM g') vs) >>= g
168 g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
190 g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
169 g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
191 g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
170 g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
192 g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
@@ -178,33 +200,51 @@ everywhereOnValuesM f g h = (f', g', h')
178 g' (PositionedValue pos com v) = (PositionedValue pos com <$> g' v) >>= g
200 g' (PositionedValue pos com v) = (PositionedValue pos com <$> g' v) >>= g
179 g' other = g other
201 g' other = g other
203+ h' :: Binder -> m Binder
204+ h' (LiteralBinder l) = (LiteralBinder <$> lit h' l) >>= h
181 h' (ConstructorBinder ctor bs) = (ConstructorBinder ctor <$> traverse h' bs) >>= h
205 h' (ConstructorBinder ctor bs) = (ConstructorBinder ctor <$> traverse h' bs) >>= h
182 h' (BinaryNoParensBinder b1 b2 b3) = (BinaryNoParensBinder <$> h' b1 <*> h' b2 <*> h' b3) >>= h
206 h' (BinaryNoParensBinder b1 b2 b3) = (BinaryNoParensBinder <$> h' b1 <*> h' b2 <*> h' b3) >>= h
183 h' (ParensInBinder b) = (ParensInBinder <$> h' b) >>= h
207 h' (ParensInBinder b) = (ParensInBinder <$> h' b) >>= h
184− h' (ObjectBinder bs) = (ObjectBinder <$> traverse (sndM h') bs) >>= h
185− h' (ArrayBinder bs) = (ArrayBinder <$> traverse h' bs) >>= h
186 h' (NamedBinder name b) = (NamedBinder name <$> h' b) >>= h
208 h' (NamedBinder name b) = (NamedBinder name <$> h' b) >>= h
187 h' (PositionedBinder pos com b) = (PositionedBinder pos com <$> h' b) >>= h
209 h' (PositionedBinder pos com b) = (PositionedBinder pos com <$> h' b) >>= h
188 h' (TypedBinder t b) = (TypedBinder t <$> h' b) >>= h
210 h' (TypedBinder t b) = (TypedBinder t <$> h' b) >>= h
189 h' other = h other
211 h' other = h other
191− handleCaseAlternative (CaseAlternative bs val) = CaseAlternative <$> traverse h' bs
213+ lit :: (a -> m a) -> Literal a -> m (Literal a)
214+ lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
215+ lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
216+ lit _ other = pure other
218+ handleCaseAlternative :: CaseAlternative -> m CaseAlternative
219+ handleCaseAlternative (CaseAlternative bs val) =
192− <*> eitherM (traverse (pairM g' g')) g' val
222+ <*> eitherM (traverse (pairM g' g')) g' val
224+ handleDoNotationElement :: DoNotationElement -> m DoNotationElement
194 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> g' v
225 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> g' v
195 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> h' b <*> g' v
226 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> h' b <*> g' v
196 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse f' ds
227 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse f' ds
197 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
228 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
199−everythingOnValues :: (r -> r -> r) ->
230+everythingOnValues
200− (Declaration -> r) ->
233+ -> (Declaration -> r)
201− (Expr -> r) ->
234+ -> (Expr -> r)
202− (Binder -> r) ->
235+ -> (Binder -> r)
203− (CaseAlternative -> r) ->
236+ -> (CaseAlternative -> r)
204− (DoNotationElement -> r) ->
237+ -> (DoNotationElement -> r)
238+ -> ( Declaration -> r
241+ , CaseAlternative -> r
205− (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r, DoNotationElement -> r)
242+ , DoNotationElement -> r
206everythingOnValues (<>) f g h i j = (f', g', h', i', j')
244everythingOnValues (<>) f g h i j = (f', g', h', i', j')
247+ f' :: Declaration -> r
208 f' d@(DataBindingGroupDeclaration ds) = foldl (<>) (f d) (map f' ds)
248 f' d@(DataBindingGroupDeclaration ds) = foldl (<>) (f d) (map f' ds)
209 f' d@(ValueDeclaration _ _ bs (Right val)) = foldl (<>) (f d) (map h' bs) <> g' val
249 f' d@(ValueDeclaration _ _ bs (Right val)) = foldl (<>) (f d) (map h' bs) <> g' val
210 f' d@(ValueDeclaration _ _ bs (Left gs)) = foldl (<>) (f d) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
250 f' d@(ValueDeclaration _ _ bs (Left gs)) = foldl (<>) (f d) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
@@ -214,13 +254,13 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
214 f' d@(PositionedDeclaration _ _ d1) = f d <> f' d1
254 f' d@(PositionedDeclaration _ _ d1) = f d <> f' d1
215 f' d = f d
255 f' d = f d
258+ g' v@(Literal l) = lit (g v) g' l
217 g' v@(UnaryMinus v1) = g v <> g' v1
259 g' v@(UnaryMinus v1) = g v <> g' v1
218 g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
260 g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
219 g' v@(Parens v1) = g v <> g' v1
261 g' v@(Parens v1) = g v <> g' v1
220 g' v@(OperatorSection op (Left v1)) = g v <> g' op <> g' v1
262 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
263 g' v@(OperatorSection op (Right v1)) = g v <> g' op <> g' v1
222− g' v@(ArrayLiteral vs) = foldl (<>) (g v) (map g' vs)
223− g' v@(ObjectLiteral vs) = foldl (<>) (g v) (map (g' . snd) vs)
224 g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
264 g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
225 g' v@(Accessor _ v1) = g v <> g' v1
265 g' v@(Accessor _ v1) = g v <> g' v1
226 g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
266 g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
@@ -234,42 +274,53 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
234 g' v@(PositionedValue _ _ v1) = g v <> g' v1
274 g' v@(PositionedValue _ _ v1) = g v <> g' v1
235 g' v = g v
275 g' v = g v
278+ h' b@(LiteralBinder l) = lit (h b) h' l
237 h' b@(ConstructorBinder _ bs) = foldl (<>) (h b) (map h' bs)
279 h' b@(ConstructorBinder _ bs) = foldl (<>) (h b) (map h' bs)
238 h' b@(BinaryNoParensBinder b1 b2 b3) = h b <> h' b1 <> h' b2 <> h' b3
280 h' b@(BinaryNoParensBinder b1 b2 b3) = h b <> h' b1 <> h' b2 <> h' b3
239 h' b@(ParensInBinder b1) = h b <> h' b1
281 h' b@(ParensInBinder b1) = h b <> h' b1
240− h' b@(ObjectBinder bs) = foldl (<>) (h b) (map (h' . snd) bs)
241− h' b@(ArrayBinder bs) = foldl (<>) (h b) (map h' bs)
242 h' b@(NamedBinder _ b1) = h b <> h' b1
282 h' b@(NamedBinder _ b1) = h b <> h' b1
243 h' b@(PositionedBinder _ _ b1) = h b <> h' b1
283 h' b@(PositionedBinder _ _ b1) = h b <> h' b1
244 h' b@(TypedBinder _ b1) = h b <> h' b1
284 h' b@(TypedBinder _ b1) = h b <> h' b1
245 h' b = h b
285 h' b = h b
287+ lit :: r -> (a -> r) -> Literal a -> r
288+ lit r go (ArrayLiteral as) = foldl (<>) r (map go as)
289+ lit r go (ObjectLiteral as) = foldl (<>) r (map (go . snd) as)
292+ i' :: CaseAlternative -> r
247 i' ca@(CaseAlternative bs (Right val)) = foldl (<>) (i ca) (map h' bs) <> g' val
293 i' ca@(CaseAlternative bs (Right val)) = foldl (<>) (i ca) (map h' bs) <> g' val
248 i' ca@(CaseAlternative bs (Left gs)) = foldl (<>) (i ca) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
294 i' ca@(CaseAlternative bs (Left gs)) = foldl (<>) (i ca) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
296+ j' :: DoNotationElement -> r
250 j' e@(DoNotationValue v) = j e <> g' v
297 j' e@(DoNotationValue v) = j e <> g' v
251 j' e@(DoNotationBind b v) = j e <> h' b <> g' v
298 j' e@(DoNotationBind b v) = j e <> h' b <> g' v
252 j' e@(DoNotationLet ds) = foldl (<>) (j e) (map f' ds)
299 j' e@(DoNotationLet ds) = foldl (<>) (j e) (map f' ds)
253 j' e@(PositionedDoNotationElement _ _ e1) = j e <> j' e1
300 j' e@(PositionedDoNotationElement _ _ e1) = j e <> j' e1
255−everythingWithContextOnValues ::
302+everythingWithContextOnValues
256− s ->
303+ :: forall s r
258− (r -> r -> r) ->
306+ -> (r -> r -> r)
259− (s -> Declaration -> (s, r)) ->
307+ -> (s -> Declaration -> (s, r))
260− (s -> Expr -> (s, r)) ->
308+ -> (s -> Expr -> (s, r))
261− (s -> Binder -> (s, r)) ->
309+ -> (s -> Binder -> (s, r))
262− (s -> CaseAlternative -> (s, r)) ->
310+ -> (s -> CaseAlternative -> (s, r))
263− (s -> DoNotationElement -> (s, r)) ->
311+ -> (s -> DoNotationElement -> (s, r))
264− ( Declaration -> r
312+ -> ( Declaration -> r
265− , Expr -> r
313+ , Expr -> r
266− , Binder -> r
314+ , Binder -> r
267− , CaseAlternative -> r
315+ , CaseAlternative -> r
268− , DoNotationElement -> r)
316+ , DoNotationElement -> r)
269everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
317everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
320+ f'' :: s -> Declaration -> r
271 f'' s d = let (s', r) = f s d in r <> f' s' d
321 f'' s d = let (s', r) = f s d in r <> f' s' d
323+ f' :: s -> Declaration -> r
273 f' s (DataBindingGroupDeclaration ds) = foldl (<>) r0 (map (f'' s) ds)
324 f' s (DataBindingGroupDeclaration ds) = foldl (<>) r0 (map (f'' s) ds)
274 f' s (ValueDeclaration _ _ bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
325 f' s (ValueDeclaration _ _ bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
275 f' s (ValueDeclaration _ _ bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
326 f' s (ValueDeclaration _ _ bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
@@ -279,15 +330,16 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
279 f' s (PositionedDeclaration _ _ d1) = f'' s d1
330 f' s (PositionedDeclaration _ _ d1) = f'' s d1
280 f' _ _ = r0
331 f' _ _ = r0
333+ g'' :: s -> Expr -> r
282 g'' s v = let (s', r) = g s v in r <> g' s' v
334 g'' s v = let (s', r) = g s v in r <> g' s' v
336+ g' :: s -> Expr -> r
337+ g' s (Literal l) = lit g'' s l
284 g' s (UnaryMinus v1) = g'' s v1
338 g' s (UnaryMinus v1) = g'' s v1
285 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
339 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
286 g' s (Parens v1) = g'' s v1
340 g' s (Parens v1) = g'' s v1
287 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
341 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
342 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
289− g' s (ArrayLiteral vs) = foldl (<>) r0 (map (g'' s) vs)
290− g' s (ObjectLiteral vs) = foldl (<>) r0 (map (g'' s . snd) vs)
291 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
343 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
292 g' s (Accessor _ v1) = g'' s v1
344 g' s (Accessor _ v1) = g'' s v1
293 g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
345 g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
@@ -301,42 +353,54 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
301 g' s (PositionedValue _ _ v1) = g'' s v1
353 g' s (PositionedValue _ _ v1) = g'' s v1
302 g' _ _ = r0
354 g' _ _ = r0
356+ h'' :: s -> Binder -> r
304 h'' s b = let (s', r) = h s b in r <> h' s' b
357 h'' s b = let (s', r) = h s b in r <> h' s' b
359+ h' :: s -> Binder -> r
360+ h' s (LiteralBinder l) = lit h'' s l
306 h' s (ConstructorBinder _ bs) = foldl (<>) r0 (map (h'' s) bs)
361 h' s (ConstructorBinder _ bs) = foldl (<>) r0 (map (h'' s) bs)
307 h' s (BinaryNoParensBinder b1 b2 b3) = h'' s b1 <> h'' s b2 <> h'' s b3
362 h' s (BinaryNoParensBinder b1 b2 b3) = h'' s b1 <> h'' s b2 <> h'' s b3
308 h' s (ParensInBinder b) = h'' s b
363 h' s (ParensInBinder b) = h'' s b
309− h' s (ObjectBinder bs) = foldl (<>) r0 (map (h'' s . snd) bs)
310− h' s (ArrayBinder bs) = foldl (<>) r0 (map (h'' s) bs)
311 h' s (NamedBinder _ b1) = h'' s b1
364 h' s (NamedBinder _ b1) = h'' s b1
312 h' s (PositionedBinder _ _ b1) = h'' s b1
365 h' s (PositionedBinder _ _ b1) = h'' s b1
313 h' s (TypedBinder _ b1) = h'' s b1
366 h' s (TypedBinder _ b1) = h'' s b1
314 h' _ _ = r0
367 h' _ _ = r0
369+ lit :: (s -> a -> r) -> s -> Literal a -> r
370+ lit go s (ArrayLiteral as) = foldl (<>) r0 (map (go s) as)
371+ lit go s (ObjectLiteral as) = foldl (<>) r0 (map (go s . snd) as)
374+ i'' :: s -> CaseAlternative -> r
316 i'' s ca = let (s', r) = i s ca in r <> i' s' ca
375 i'' s ca = let (s', r) = i s ca in r <> i' s' ca
377+ i' :: s -> CaseAlternative -> r
318 i' s (CaseAlternative bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
378 i' s (CaseAlternative bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
319 i' s (CaseAlternative bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
379 i' s (CaseAlternative bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
381+ j'' :: s -> DoNotationElement -> r
321 j'' s e = let (s', r) = j s e in r <> j' s' e
382 j'' s e = let (s', r) = j s e in r <> j' s' e
384+ j' :: s -> DoNotationElement -> r
323 j' s (DoNotationValue v) = g'' s v
385 j' s (DoNotationValue v) = g'' s v
324 j' s (DoNotationBind b v) = h'' s b <> g'' s v
386 j' s (DoNotationBind b v) = h'' s b <> g'' s v
325 j' s (DoNotationLet ds) = foldl (<>) r0 (map (f'' s) ds)
387 j' s (DoNotationLet ds) = foldl (<>) r0 (map (f'' s) ds)
326 j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
388 j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
328−everywhereWithContextOnValuesM :: (Functor m, Applicative m, Monad m) =>
390+everywhereWithContextOnValuesM
329− s ->
391+ :: forall m s
392+ . (Functor m, Applicative m, Monad m)
330− (s -> Declaration -> m (s, Declaration)) ->
394+ -> (s -> Declaration -> m (s, Declaration))
331− (s -> Expr -> m (s, Expr)) ->
395+ -> (s -> Expr -> m (s, Expr))
332− (s -> Binder -> m (s, Binder)) ->
396+ -> (s -> Binder -> m (s, Binder))
333− (s -> CaseAlternative -> m (s, CaseAlternative)) ->
397+ -> (s -> CaseAlternative -> m (s, CaseAlternative))
334− (s -> DoNotationElement -> m (s, DoNotationElement)) ->
398+ -> (s -> DoNotationElement -> m (s, DoNotationElement))
335− ( Declaration -> m Declaration
399+ -> ( Declaration -> m Declaration
336− , Expr -> m Expr
400+ , Expr -> m Expr
337− , Binder -> m Binder
401+ , Binder -> m Binder
338− , CaseAlternative -> m CaseAlternative
402+ , CaseAlternative -> m CaseAlternative
339− , DoNotationElement -> m DoNotationElement)
403+ , DoNotationElement -> m DoNotationElement)
340everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
404everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
342 f'' s = uncurry f' <=< f s
406 f'' s = uncurry f' <=< f s
@@ -351,13 +415,12 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
352 g'' s = uncurry g' <=< g s
416 g'' s = uncurry g' <=< g s
418+ g' s (Literal l) = Literal <$> lit g'' s l
354 g' s (UnaryMinus v) = UnaryMinus <$> g'' s v
419 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
420 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
421 g' s (Parens v) = Parens <$> g'' s v
357 g' s (OperatorSection op (Left v)) = OperatorSection <$> g'' s op <*> (Left <$> g'' s v)
422 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)
423 g' s (OperatorSection op (Right v)) = OperatorSection <$> g'' s op <*> (Right <$> g'' s v)
359− g' s (ArrayLiteral vs) = ArrayLiteral <$> traverse (g'' s) vs
360− g' s (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g'' s)) vs
361 g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
424 g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
362 g' s (Accessor prop v) = Accessor prop <$> g'' s v
425 g' s (Accessor prop v) = Accessor prop <$> g'' s v
363 g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
426 g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
@@ -373,16 +436,20 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
374 h'' s = uncurry h' <=< h s
437 h'' s = uncurry h' <=< h s
439+ h' s (LiteralBinder l) = LiteralBinder <$> lit h'' s l
376 h' s (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h'' s) bs
440 h' s (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h'' s) bs
377 h' s (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> h'' s b1 <*> h'' s b2 <*> h'' s b3
441 h' s (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> h'' s b1 <*> h'' s b2 <*> h'' s b3
378 h' s (ParensInBinder b) = ParensInBinder <$> h'' s b
442 h' s (ParensInBinder b) = ParensInBinder <$> h'' s b
379− h' s (ObjectBinder bs) = ObjectBinder <$> traverse (sndM (h'' s)) bs
380− h' s (ArrayBinder bs) = ArrayBinder <$> traverse (h'' s) bs
381 h' s (NamedBinder name b) = NamedBinder name <$> h'' s b
443 h' s (NamedBinder name b) = NamedBinder name <$> h'' s b
382 h' s (PositionedBinder pos com b) = PositionedBinder pos com <$> h'' s b
444 h' s (PositionedBinder pos com b) = PositionedBinder pos com <$> h'' s b
383 h' s (TypedBinder t b) = TypedBinder t <$> h'' s b
445 h' s (TypedBinder t b) = TypedBinder t <$> h'' s b
384 h' _ other = return other
446 h' _ other = return other
448+ lit :: (s -> a -> m a) -> s -> Literal a -> m (Literal a)
449+ lit go s (ArrayLiteral as) = ArrayLiteral <$> traverse (go s) as
450+ lit go s (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM (go s)) as
451+ lit _ _ other = return other
386 i'' s = uncurry i' <=< i s
453 i'' s = uncurry i' <=< i s
388 i' s (CaseAlternative bs val) = CaseAlternative <$> traverse (h'' s) bs <*> eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
455 i' s (CaseAlternative bs val) = CaseAlternative <$> traverse (h'' s) bs <*> eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
@@ -394,25 +461,29 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
394 j' s (DoNotationLet ds) = DoNotationLet <$> traverse (f'' s) ds
461 j' s (DoNotationLet ds) = DoNotationLet <$> traverse (f'' s) ds
395 j' s (PositionedDoNotationElement pos com e1) = PositionedDoNotationElement pos com <$> j'' s e1
462 j' s (PositionedDoNotationElement pos com e1) = PositionedDoNotationElement pos com <$> j'' s e1
397−everythingWithScope ::
464+everythingWithScope
398− (Monoid r) =>
466+ . (Monoid r)
399− (S.Set Ident -> Declaration -> r) ->
467+ => (S.Set Ident -> Declaration -> r)
400− (S.Set Ident -> Expr -> r) ->
468+ -> (S.Set Ident -> Expr -> r)
401− (S.Set Ident -> Binder -> r) ->
469+ -> (S.Set Ident -> Binder -> r)
402− (S.Set Ident -> CaseAlternative -> r) ->
470+ -> (S.Set Ident -> CaseAlternative -> r)
403− (S.Set Ident -> DoNotationElement -> r) ->
471+ -> (S.Set Ident -> DoNotationElement -> r)
404− ( S.Set Ident -> Declaration -> r
472+ -> ( S.Set Ident -> Declaration -> r
405− , S.Set Ident -> Expr -> r
473+ , S.Set Ident -> Expr -> r
406− , S.Set Ident -> Binder -> r
474+ , S.Set Ident -> Binder -> r
407− , S.Set Ident -> CaseAlternative -> r
475+ , S.Set Ident -> CaseAlternative -> r
408− , S.Set Ident -> DoNotationElement -> r)
476+ , S.Set Ident -> DoNotationElement -> r
409everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
478everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
411 -- Avoid importing Data.Monoid and getting shadowed names above
480 -- Avoid importing Data.Monoid and getting shadowed names above
412 (<>) = mappend
481 (<>) = mappend
483+ f'' :: S.Set Ident -> Declaration -> r
414 f'' s a = f s a <> f' s a
484 f'' s a = f s a <> f' s a
486+ f' :: S.Set Ident -> Declaration -> r
416 f' s (DataBindingGroupDeclaration ds) =
487 f' s (DataBindingGroupDeclaration ds) =
417 let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
488 let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
418 in foldMap (f'' s') ds
489 in foldMap (f'' s') ds
@@ -431,15 +502,16 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
431 f' s (PositionedDeclaration _ _ d) = f'' s d
502 f' s (PositionedDeclaration _ _ d) = f'' s d
432 f' _ _ = mempty
503 f' _ _ = mempty
505+ g'' :: S.Set Ident -> Expr -> r
434 g'' s a = g s a <> g' s a
506 g'' s a = g s a <> g' s a
508+ g' :: S.Set Ident -> Expr -> r
509+ g' s (Literal l) = lit g'' s l
436 g' s (UnaryMinus v1) = g'' s v1
510 g' s (UnaryMinus v1) = g'' s v1
437 g' s (BinaryNoParens op v1 v2) = g' s op <> g' s v1 <> g' s v2
511 g' s (BinaryNoParens op v1 v2) = g' s op <> g' s v1 <> g' s v2
438 g' s (Parens v1) = g'' s v1
512 g' s (Parens v1) = g'' s v1
439 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
513 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
514 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
441− g' s (ArrayLiteral vs) = foldMap (g'' s) vs
442− g' s (ObjectLiteral vs) = foldMap (g'' s . snd) vs
443 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
515 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
444 g' s (Accessor _ v1) = g'' s v1
516 g' s (Accessor _ v1) = g'' s v1
445 g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
517 g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
@@ -460,20 +532,28 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
460 g' s (PositionedValue _ _ v1) = g'' s v1
532 g' s (PositionedValue _ _ v1) = g'' s v1
461 g' _ _ = mempty
533 g' _ _ = mempty
535+ h'' :: S.Set Ident -> Binder -> r
463 h'' s a = h s a <> h' s a
536 h'' s a = h s a <> h' s a
538+ h' :: S.Set Ident -> Binder -> r
539+ h' s (LiteralBinder l) = lit h'' s l
465 h' s (ConstructorBinder _ bs) = foldMap (h'' s) bs
540 h' s (ConstructorBinder _ bs) = foldMap (h'' s) bs
466 h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
541 h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
467 h' s (ParensInBinder b) = h'' s b
542 h' s (ParensInBinder b) = h'' s b
468− h' s (ObjectBinder bs) = foldMap (h'' s . snd) bs
469− h' s (ArrayBinder bs) = foldMap (h'' s) bs
470 h' s (NamedBinder name b1) = h'' (S.insert name s) b1
543 h' s (NamedBinder name b1) = h'' (S.insert name s) b1
471 h' s (PositionedBinder _ _ b1) = h'' s b1
544 h' s (PositionedBinder _ _ b1) = h'' s b1
472 h' s (TypedBinder _ b1) = h'' s b1
545 h' s (TypedBinder _ b1) = h'' s b1
473 h' _ _ = mempty
546 h' _ _ = mempty
548+ lit :: (S.Set Ident -> a -> r) -> S.Set Ident -> Literal a -> r
549+ lit go s (ArrayLiteral as) = foldMap (go s) as
550+ lit go s (ObjectLiteral as) = foldMap (go s . snd) as
553+ i'' :: S.Set Ident -> CaseAlternative -> r
475 i'' s a = i s a <> i' s a
554 i'' s a = i s a <> i' s a
556+ i' :: S.Set Ident -> CaseAlternative -> r
477 i' s (CaseAlternative bs (Right val)) =
557 i' s (CaseAlternative bs (Right val)) =
478 let s' = S.union s (S.fromList (concatMap binderNames bs))
558 let s' = S.union s (S.fromList (concatMap binderNames bs))
479 in foldMap (h'' s) bs <> g'' s' val
559 in foldMap (h'' s) bs <> g'' s' val
@@ -481,8 +561,10 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
481 let s' = S.union s (S.fromList (concatMap binderNames bs))
561 let s' = S.union s (S.fromList (concatMap binderNames bs))
482 in foldMap (h'' s) bs <> foldMap (\(grd, val) -> g'' s' grd <> g'' s' val) gs
562 in foldMap (h'' s) bs <> foldMap (\(grd, val) -> g'' s' grd <> g'' s' val) gs
564+ j'' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
484 j'' s a = let (s', r) = j' s a in (s', j s a <> r)
565 j'' s a = let (s', r) = j' s a in (s', j s a <> r)
567+ j' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
486 j' s (DoNotationValue v) = (s, g'' s v)
568 j' s (DoNotationValue v) = (s, g'' s v)
487 j' s (DoNotationBind b v) =
569 j' s (DoNotationBind b v) =
488 let s' = S.union (S.fromList (binderNames b)) s
570 let s' = S.union (S.fromList (binderNames b)) s
@@ -498,7 +580,15 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
498 getDeclIdent (TypeDeclaration ident _) = Just ident
580 getDeclIdent (TypeDeclaration ident _) = Just ident
499 getDeclIdent _ = Nothing
581 getDeclIdent _ = Nothing
501−accumTypes :: (Monoid r) => (Type -> r) -> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r, DoNotationElement -> r)
583+accumTypes
586+ -> ( Declaration -> r
589+ , CaseAlternative -> r
590+ , DoNotationElement -> r
502accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
592accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
504 forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
594 forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)