@@ -447,3 +447,62 @@ binderNames = everything (++) (mkQ [] go)
447 go (VarBinder ident) = [ident]
447 go (VarBinder ident) = [ident]
448 go (NamedBinder ident _) = [ident]
448 go (NamedBinder ident _) = [ident]
449 go _ = []
449 go _ = []
455+everywhereOnValues :: (Declaration -> Declaration) ->
457+ (Binder -> Binder) ->
458+ (Declaration -> Declaration, Value -> Value, Binder -> Binder)
459+everywhereOnValues f g h = (f', g', h')
461+ f' :: Declaration -> Declaration
462+ f' (DataBindingGroupDeclaration ds) = f (DataBindingGroupDeclaration (map f' ds))
463+ f' (ValueDeclaration name nameKind bs grd val) = f (ValueDeclaration name nameKind (map h' bs) (fmap g' grd) (g' val))
464+ f' (BindingGroupDeclaration ds) = f (BindingGroupDeclaration (map (\(name, nameKind, val) -> (name, nameKind, g' val)) ds))
465+ f' (TypeClassDeclaration name args implies ds) = f (TypeClassDeclaration name args implies (map f' ds))
466+ f' (TypeInstanceDeclaration name cs className args ds) = f (TypeInstanceDeclaration name cs className args (map f' ds))
467+ f' (PositionedDeclaration pos d) = f (PositionedDeclaration pos (f' d))
470+ g' :: Value -> Value
471+ g' (UnaryMinus v) = g (UnaryMinus (g' v))
472+ g' (BinaryNoParens op v1 v2) = g (BinaryNoParens op (g' v1) (g' v2))
473+ g' (Parens v) = g (Parens (g' v))
474+ g' (ArrayLiteral vs) = g (ArrayLiteral (map g' vs))
475+ g' (ObjectLiteral vs) = g (ObjectLiteral (map (fmap g') vs))
476+ g' (Accessor prop v) = g (Accessor prop (g' v))
477+ g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
478+ g' (Abs name v) = g (Abs name (g' v))
479+ g' (App v1 v2) = g (App (g' v1) (g' v2))
480+ g' (IfThenElse v1 v2 v3) = g (IfThenElse (g' v1) (g' v2) (g' v3))
481+ g' (Case vs alts) = g (Case (map g' vs) (map handleCaseAlternative alts))
482+ g' (TypedValue check v ty) = g (TypedValue check (g' v) ty)
483+ g' (Let ds v) = g (Let (map f' ds) (g' v))
484+ g' (Do es) = g (Do (map handleDoNotationElement es))
485+ g' (PositionedValue pos v) = g (PositionedValue pos (g' v))
488+ h' :: Binder -> Binder
489+ h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
490+ h' (ObjectBinder bs) = h (ObjectBinder (map (fmap h') bs))
491+ h' (ArrayBinder bs) = h (ArrayBinder (map h' bs))
492+ h' (ConsBinder b1 b2) = h (ConsBinder (h' b1) (h' b2))
493+ h' (NamedBinder name b) = h (NamedBinder name (h' b))
494+ h' (PositionedBinder pos b) = h (PositionedBinder pos (h' b))
497+ handleCaseAlternative :: CaseAlternative -> CaseAlternative
498+ handleCaseAlternative ca =
499+ ca { caseAlternativeBinders = map h' (caseAlternativeBinders ca)
500+ , caseAlternativeGuard = fmap g' (caseAlternativeGuard ca)
501+ , caseAlternativeResult = g' (caseAlternativeResult ca)
504+ handleDoNotationElement :: DoNotationElement -> DoNotationElement
505+ handleDoNotationElement (DoNotationValue v) = DoNotationValue (g' v)
506+ handleDoNotationElement (DoNotationBind b v) = DoNotationBind (h' b) (g' v)
507+ handleDoNotationElement (DoNotationLet ds) = DoNotationLet (map f' ds)
508+ handleDoNotationElement (PositionedDoNotationElement pos e) = PositionedDoNotationElement pos (handleDoNotationElement e)