-- |
-- AST traversal helpers
--
module Language.PureScript.AST.Traversals where

import Prelude.Compat

import Control.Monad

import Data.Foldable (fold)
import Data.List (mapAccumL)
import Data.Maybe (mapMaybe)
import qualified Data.List.NonEmpty as NEL
import qualified Data.Map as M
import qualified Data.Set as S

import Language.PureScript.AST.Binders
import Language.PureScript.AST.Declarations
import Language.PureScript.AST.Literals
import Language.PureScript.Names
import Language.PureScript.Traversals
import Language.PureScript.TypeClassDictionaries (TypeClassDictionaryInScope(..))
import Language.PureScript.Types

guardedExprM :: Applicative m
             => (Guard -> m Guard)
             -> (Expr -> m Expr)
             -> GuardedExpr
             -> m GuardedExpr
guardedExprM :: (Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
f Expr -> m Expr
g (GuardedExpr [Guard]
guards Expr
rhs) =
  [Guard] -> Expr -> GuardedExpr
GuardedExpr ([Guard] -> Expr -> GuardedExpr)
-> m [Guard] -> m (Expr -> GuardedExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Guard -> m Guard) -> [Guard] -> m [Guard]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Guard -> m Guard
f [Guard]
guards m (Expr -> GuardedExpr) -> m Expr -> m GuardedExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g Expr
rhs

mapGuardedExpr :: (Guard -> Guard)
               -> (Expr -> Expr)
               -> GuardedExpr
               -> GuardedExpr
mapGuardedExpr :: (Guard -> Guard) -> (Expr -> Expr) -> GuardedExpr -> GuardedExpr
mapGuardedExpr Guard -> Guard
f Expr -> Expr
g (GuardedExpr [Guard]
guards Expr
rhs) =
  [Guard] -> Expr -> GuardedExpr
GuardedExpr ((Guard -> Guard) -> [Guard] -> [Guard]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Guard -> Guard
f [Guard]
guards) (Expr -> Expr
g Expr
rhs)

litM :: Monad m => (a -> m a) -> Literal a -> m (Literal a)
litM :: (a -> m a) -> Literal a -> m (Literal a)
litM a -> m a
go (ObjectLiteral [(PSString, a)]
as) = [(PSString, a)] -> Literal a
forall a. [(PSString, a)] -> Literal a
ObjectLiteral ([(PSString, a)] -> Literal a)
-> m [(PSString, a)] -> m (Literal a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((PSString, a) -> m (PSString, a))
-> [(PSString, a)] -> m [(PSString, a)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((a -> m a) -> (PSString, a) -> m (PSString, a)
forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM a -> m a
go) [(PSString, a)]
as
litM a -> m a
go (ArrayLiteral [a]
as) = [a] -> Literal a
forall a. [a] -> Literal a
ArrayLiteral ([a] -> Literal a) -> m [a] -> m (Literal a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> m a) -> [a] -> m [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m a
go [a]
as
litM a -> m a
_ Literal a
other = Literal a -> m (Literal a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Literal a
other

everywhereOnValues
  :: (Declaration -> Declaration)
  -> (Expr -> Expr)
  -> (Binder -> Binder)
  -> ( Declaration -> Declaration
     , Expr -> Expr
     , Binder -> Binder
     )
everywhereOnValues :: (Declaration -> Declaration)
-> (Expr -> Expr)
-> (Binder -> Binder)
-> (Declaration -> Declaration, Expr -> Expr, Binder -> Binder)
everywhereOnValues Declaration -> Declaration
f Expr -> Expr
g Binder -> Binder
h = (Declaration -> Declaration
f', Expr -> Expr
g', Binder -> Binder
h')
  where
  f' :: Declaration -> Declaration
  f' :: Declaration -> Declaration
f' (DataBindingGroupDeclaration NonEmpty Declaration
ds) = Declaration -> Declaration
f (NonEmpty Declaration -> Declaration
DataBindingGroupDeclaration ((Declaration -> Declaration)
-> NonEmpty Declaration -> NonEmpty Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f' NonEmpty Declaration
ds))
  f' (ValueDecl SourceAnn
sa Ident
name NameKind
nameKind [Binder]
bs [GuardedExpr]
val) =
     Declaration -> Declaration
f (SourceAnn
-> Ident -> NameKind -> [Binder] -> [GuardedExpr] -> Declaration
ValueDecl SourceAnn
sa Ident
name NameKind
nameKind ((Binder -> Binder) -> [Binder] -> [Binder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> Binder
h' [Binder]
bs) ((GuardedExpr -> GuardedExpr) -> [GuardedExpr] -> [GuardedExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Guard -> Guard) -> (Expr -> Expr) -> GuardedExpr -> GuardedExpr
mapGuardedExpr Guard -> Guard
handleGuard Expr -> Expr
g') [GuardedExpr]
val))
  f' (BoundValueDeclaration SourceAnn
sa Binder
b Expr
expr) = Declaration -> Declaration
f (SourceAnn -> Binder -> Expr -> Declaration
BoundValueDeclaration SourceAnn
sa (Binder -> Binder
h' Binder
b) (Expr -> Expr
g' Expr
expr))
  f' (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = Declaration -> Declaration
f (NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration
BindingGroupDeclaration ((((SourceAnn, Ident), NameKind, Expr)
 -> ((SourceAnn, Ident), NameKind, Expr))
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((SourceAnn, Ident)
name, NameKind
nameKind, Expr
val) -> ((SourceAnn, Ident)
name, NameKind
nameKind, Expr -> Expr
g' Expr
val)) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds))
  f' (TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps [Declaration]
ds) = Declaration -> Declaration
f (SourceAnn
-> ProperName 'ClassName
-> [(Text, Maybe SourceType)]
-> [SourceConstraint]
-> [FunctionalDependency]
-> [Declaration]
-> Declaration
TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps ((Declaration -> Declaration) -> [Declaration] -> [Declaration]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f' [Declaration]
ds))
  f' (TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = Declaration -> Declaration
f (SourceAnn
-> [Ident]
-> Integer
-> Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args (([Declaration] -> [Declaration])
-> TypeInstanceBody -> TypeInstanceBody
mapTypeInstanceBody ((Declaration -> Declaration) -> [Declaration] -> [Declaration]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f') TypeInstanceBody
ds))
  f' Declaration
other = Declaration -> Declaration
f Declaration
other

  g' :: Expr -> Expr
  g' :: Expr -> Expr
g' (Literal SourceSpan
ss Literal Expr
l) = Expr -> Expr
g (SourceSpan -> Literal Expr -> Expr
Literal SourceSpan
ss ((Expr -> Expr) -> Literal Expr -> Literal Expr
forall a. (a -> a) -> Literal a -> Literal a
lit Expr -> Expr
g' Literal Expr
l))
  g' (UnaryMinus SourceSpan
ss Expr
v) = Expr -> Expr
g (SourceSpan -> Expr -> Expr
UnaryMinus SourceSpan
ss (Expr -> Expr
g' Expr
v))
  g' (BinaryNoParens Expr
op Expr
v1 Expr
v2) = Expr -> Expr
g (Expr -> Expr -> Expr -> Expr
BinaryNoParens (Expr -> Expr
g' Expr
op) (Expr -> Expr
g' Expr
v1) (Expr -> Expr
g' Expr
v2))
  g' (Parens Expr
v) = Expr -> Expr
g (Expr -> Expr
Parens (Expr -> Expr
g' Expr
v))
  g' (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name Expr
v) = Expr -> Expr
g (Qualified (ProperName 'ClassName) -> Expr -> Expr
TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name (Expr -> Expr
g' Expr
v))
  g' (Accessor PSString
prop Expr
v) = Expr -> Expr
g (PSString -> Expr -> Expr
Accessor PSString
prop (Expr -> Expr
g' Expr
v))
  g' (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = Expr -> Expr
g (Expr -> [(PSString, Expr)] -> Expr
ObjectUpdate (Expr -> Expr
g' Expr
obj) (((PSString, Expr) -> (PSString, Expr))
-> [(PSString, Expr)] -> [(PSString, Expr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Expr -> Expr) -> (PSString, Expr) -> (PSString, Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> Expr
g') [(PSString, Expr)]
vs))
  g' (ObjectUpdateNested Expr
obj PathTree Expr
vs) = Expr -> Expr
g (Expr -> PathTree Expr -> Expr
ObjectUpdateNested (Expr -> Expr
g' Expr
obj) ((Expr -> Expr) -> PathTree Expr -> PathTree Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> Expr
g' PathTree Expr
vs))
  g' (Abs Binder
binder Expr
v) = Expr -> Expr
g (Binder -> Expr -> Expr
Abs (Binder -> Binder
h' Binder
binder) (Expr -> Expr
g' Expr
v))
  g' (App Expr
v1 Expr
v2) = Expr -> Expr
g (Expr -> Expr -> Expr
App (Expr -> Expr
g' Expr
v1) (Expr -> Expr
g' Expr
v2))
  g' (Unused Expr
v) = Expr -> Expr
g (Expr -> Expr
Unused (Expr -> Expr
g' Expr
v))
  g' (IfThenElse Expr
v1 Expr
v2 Expr
v3) = Expr -> Expr
g (Expr -> Expr -> Expr -> Expr
IfThenElse (Expr -> Expr
g' Expr
v1) (Expr -> Expr
g' Expr
v2) (Expr -> Expr
g' Expr
v3))
  g' (Case [Expr]
vs [CaseAlternative]
alts) = Expr -> Expr
g ([Expr] -> [CaseAlternative] -> Expr
Case ((Expr -> Expr) -> [Expr] -> [Expr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> Expr
g' [Expr]
vs) ((CaseAlternative -> CaseAlternative)
-> [CaseAlternative] -> [CaseAlternative]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CaseAlternative -> CaseAlternative
handleCaseAlternative [CaseAlternative]
alts))
  g' (TypedValue Bool
check Expr
v SourceType
ty) = Expr -> Expr
g (Bool -> Expr -> SourceType -> Expr
TypedValue Bool
check (Expr -> Expr
g' Expr
v) SourceType
ty)
  g' (Let WhereProvenance
w [Declaration]
ds Expr
v) = Expr -> Expr
g (WhereProvenance -> [Declaration] -> Expr -> Expr
Let WhereProvenance
w ((Declaration -> Declaration) -> [Declaration] -> [Declaration]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f' [Declaration]
ds) (Expr -> Expr
g' Expr
v))
  g' (Do Maybe ModuleName
m [DoNotationElement]
es) = Expr -> Expr
g (Maybe ModuleName -> [DoNotationElement] -> Expr
Do Maybe ModuleName
m ((DoNotationElement -> DoNotationElement)
-> [DoNotationElement] -> [DoNotationElement]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoNotationElement -> DoNotationElement
handleDoNotationElement [DoNotationElement]
es))
  g' (Ado Maybe ModuleName
m [DoNotationElement]
es Expr
v) = Expr -> Expr
g (Maybe ModuleName -> [DoNotationElement] -> Expr -> Expr
Ado Maybe ModuleName
m ((DoNotationElement -> DoNotationElement)
-> [DoNotationElement] -> [DoNotationElement]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoNotationElement -> DoNotationElement
handleDoNotationElement [DoNotationElement]
es) (Expr -> Expr
g' Expr
v))
  g' (PositionedValue SourceSpan
pos [Comment]
com Expr
v) = Expr -> Expr
g (SourceSpan -> [Comment] -> Expr -> Expr
PositionedValue SourceSpan
pos [Comment]
com (Expr -> Expr
g' Expr
v))
  g' Expr
other = Expr -> Expr
g Expr
other

  h' :: Binder -> Binder
  h' :: Binder -> Binder
h' (ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor [Binder]
bs) = Binder -> Binder
h (SourceSpan
-> Qualified (ProperName 'ConstructorName) -> [Binder] -> Binder
ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor ((Binder -> Binder) -> [Binder] -> [Binder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> Binder
h' [Binder]
bs))
  h' (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = Binder -> Binder
h (Binder -> Binder -> Binder -> Binder
BinaryNoParensBinder (Binder -> Binder
h' Binder
b1) (Binder -> Binder
h' Binder
b2) (Binder -> Binder
h' Binder
b3))
  h' (ParensInBinder Binder
b) = Binder -> Binder
h (Binder -> Binder
ParensInBinder (Binder -> Binder
h' Binder
b))
  h' (LiteralBinder SourceSpan
ss Literal Binder
l) = Binder -> Binder
h (SourceSpan -> Literal Binder -> Binder
LiteralBinder SourceSpan
ss ((Binder -> Binder) -> Literal Binder -> Literal Binder
forall a. (a -> a) -> Literal a -> Literal a
lit Binder -> Binder
h' Literal Binder
l))
  h' (NamedBinder SourceSpan
ss Ident
name Binder
b) = Binder -> Binder
h (SourceSpan -> Ident -> Binder -> Binder
NamedBinder SourceSpan
ss Ident
name (Binder -> Binder
h' Binder
b))
  h' (PositionedBinder SourceSpan
pos [Comment]
com Binder
b) = Binder -> Binder
h (SourceSpan -> [Comment] -> Binder -> Binder
PositionedBinder SourceSpan
pos [Comment]
com (Binder -> Binder
h' Binder
b))
  h' (TypedBinder SourceType
t Binder
b) = Binder -> Binder
h (SourceType -> Binder -> Binder
TypedBinder SourceType
t (Binder -> Binder
h' Binder
b))
  h' Binder
other = Binder -> Binder
h Binder
other

  lit :: (a -> a) -> Literal a -> Literal a
  lit :: (a -> a) -> Literal a -> Literal a
lit a -> a
go (ArrayLiteral [a]
as) = [a] -> Literal a
forall a. [a] -> Literal a
ArrayLiteral ((a -> a) -> [a] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
go [a]
as)
  lit a -> a
go (ObjectLiteral [(PSString, a)]
as) = [(PSString, a)] -> Literal a
forall a. [(PSString, a)] -> Literal a
ObjectLiteral (((PSString, a) -> (PSString, a))
-> [(PSString, a)] -> [(PSString, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> (PSString, a) -> (PSString, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
go) [(PSString, a)]
as)
  lit a -> a
_ Literal a
other = Literal a
other

  handleCaseAlternative :: CaseAlternative -> CaseAlternative
  handleCaseAlternative :: CaseAlternative -> CaseAlternative
handleCaseAlternative CaseAlternative
ca =
    CaseAlternative
ca { caseAlternativeBinders :: [Binder]
caseAlternativeBinders = (Binder -> Binder) -> [Binder] -> [Binder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> Binder
h' (CaseAlternative -> [Binder]
caseAlternativeBinders CaseAlternative
ca)
       , caseAlternativeResult :: [GuardedExpr]
caseAlternativeResult = (GuardedExpr -> GuardedExpr) -> [GuardedExpr] -> [GuardedExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Guard -> Guard) -> (Expr -> Expr) -> GuardedExpr -> GuardedExpr
mapGuardedExpr Guard -> Guard
handleGuard Expr -> Expr
g') (CaseAlternative -> [GuardedExpr]
caseAlternativeResult CaseAlternative
ca)
       }

  handleDoNotationElement :: DoNotationElement -> DoNotationElement
  handleDoNotationElement :: DoNotationElement -> DoNotationElement
handleDoNotationElement (DoNotationValue Expr
v) = Expr -> DoNotationElement
DoNotationValue (Expr -> Expr
g' Expr
v)
  handleDoNotationElement (DoNotationBind Binder
b Expr
v) = Binder -> Expr -> DoNotationElement
DoNotationBind (Binder -> Binder
h' Binder
b) (Expr -> Expr
g' Expr
v)
  handleDoNotationElement (DoNotationLet [Declaration]
ds) = [Declaration] -> DoNotationElement
DoNotationLet ((Declaration -> Declaration) -> [Declaration] -> [Declaration]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f' [Declaration]
ds)
  handleDoNotationElement (PositionedDoNotationElement SourceSpan
pos [Comment]
com DoNotationElement
e) = SourceSpan -> [Comment] -> DoNotationElement -> DoNotationElement
PositionedDoNotationElement SourceSpan
pos [Comment]
com (DoNotationElement -> DoNotationElement
handleDoNotationElement DoNotationElement
e)

  handleGuard :: Guard -> Guard
  handleGuard :: Guard -> Guard
handleGuard (ConditionGuard Expr
e) = Expr -> Guard
ConditionGuard (Expr -> Expr
g' Expr
e)
  handleGuard (PatternGuard Binder
b Expr
e) = Binder -> Expr -> Guard
PatternGuard (Binder -> Binder
h' Binder
b) (Expr -> Expr
g' Expr
e)

everywhereOnValuesTopDownM
  :: forall m
   . (Monad m)
  => (Declaration -> m Declaration)
  -> (Expr -> m Expr)
  -> (Binder -> m Binder)
  -> ( Declaration -> m Declaration
     , Expr -> m Expr
     , Binder -> m Binder
     )
everywhereOnValuesTopDownM :: (Declaration -> m Declaration)
-> (Expr -> m Expr)
-> (Binder -> m Binder)
-> (Declaration -> m Declaration, Expr -> m Expr,
    Binder -> m Binder)
everywhereOnValuesTopDownM Declaration -> m Declaration
f Expr -> m Expr
g Binder -> m Binder
h = (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f, Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g, Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h)
  where

  f' :: Declaration -> m Declaration
  f' :: Declaration -> m Declaration
f' (DataBindingGroupDeclaration NonEmpty Declaration
ds) = NonEmpty Declaration -> Declaration
DataBindingGroupDeclaration (NonEmpty Declaration -> Declaration)
-> m (NonEmpty Declaration) -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration)
-> NonEmpty Declaration -> m (NonEmpty Declaration)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f) NonEmpty Declaration
ds
  f' (ValueDecl SourceAnn
sa Ident
name NameKind
nameKind [Binder]
bs [GuardedExpr]
val) =
     SourceAnn
-> Ident -> NameKind -> [Binder] -> [GuardedExpr] -> Declaration
ValueDecl SourceAnn
sa Ident
name NameKind
nameKind ([Binder] -> [GuardedExpr] -> Declaration)
-> m [Binder] -> m ([GuardedExpr] -> Declaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) [Binder]
bs m ([GuardedExpr] -> Declaration)
-> m [GuardedExpr] -> m Declaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g)) [GuardedExpr]
val
  f' (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration
BindingGroupDeclaration (NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
-> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (((SourceAnn, Ident), NameKind, Expr)
 -> m ((SourceAnn, Ident), NameKind, Expr))
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\((SourceAnn, Ident)
name, NameKind
nameKind, Expr
val) -> (,,) (SourceAnn, Ident)
name NameKind
nameKind (Expr -> ((SourceAnn, Ident), NameKind, Expr))
-> m Expr -> m ((SourceAnn, Ident), NameKind, Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
val m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds
  f' (TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps [Declaration]
ds) = SourceAnn
-> ProperName 'ClassName
-> [(Text, Maybe SourceType)]
-> [SourceConstraint]
-> [FunctionalDependency]
-> [Declaration]
-> Declaration
TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps ([Declaration] -> Declaration) -> m [Declaration] -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f) [Declaration]
ds
  f' (TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = SourceAnn
-> [Ident]
-> Integer
-> Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args (TypeInstanceBody -> Declaration)
-> m TypeInstanceBody -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Declaration] -> m [Declaration])
-> TypeInstanceBody -> m TypeInstanceBody
forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody ((Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f)) TypeInstanceBody
ds
  f' (BoundValueDeclaration SourceAnn
sa Binder
b Expr
expr) = SourceAnn -> Binder -> Expr -> Declaration
BoundValueDeclaration SourceAnn
sa (Binder -> Expr -> Declaration)
-> m Binder -> m (Expr -> Declaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b m (Expr -> Declaration) -> m Expr -> m Declaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) Expr
expr
  f' Declaration
other = Declaration -> m Declaration
f Declaration
other

  g' :: Expr -> m Expr
  g' :: Expr -> m Expr
g' (Literal SourceSpan
ss Literal Expr
l) = SourceSpan -> Literal Expr -> Expr
Literal SourceSpan
ss (Literal Expr -> Expr) -> m (Literal Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr) -> Literal Expr -> m (Literal Expr)
forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM (Expr -> m Expr
g (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Expr -> m Expr
g') Literal Expr
l
  g' (UnaryMinus SourceSpan
ss Expr
v) = SourceSpan -> Expr -> Expr
UnaryMinus SourceSpan
ss (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (BinaryNoParens Expr
op Expr
v1 Expr
v2) = Expr -> Expr -> Expr -> Expr
BinaryNoParens (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
op m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v1 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Parens Expr
v) = Expr -> Expr
Parens (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name Expr
v) = Qualified (ProperName 'ClassName) -> Expr -> Expr
TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Accessor PSString
prop Expr
v) = PSString -> Expr -> Expr
Accessor PSString
prop (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = Expr -> [(PSString, Expr)] -> Expr
ObjectUpdate (Expr -> [(PSString, Expr)] -> Expr)
-> m Expr -> m ([(PSString, Expr)] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
obj m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m ([(PSString, Expr)] -> Expr) -> m [(PSString, Expr)] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((PSString, Expr) -> m (PSString, Expr))
-> [(PSString, Expr)] -> m [(PSString, Expr)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr -> m Expr) -> (PSString, Expr) -> m (PSString, Expr)
forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g)) [(PSString, Expr)]
vs
  g' (ObjectUpdateNested Expr
obj PathTree Expr
vs) = Expr -> PathTree Expr -> Expr
ObjectUpdateNested (Expr -> PathTree Expr -> Expr)
-> m Expr -> m (PathTree Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
obj m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (PathTree Expr -> Expr) -> m (PathTree Expr) -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr) -> PathTree Expr -> m (PathTree Expr)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) PathTree Expr
vs
  g' (Abs Binder
binder Expr
v) = Binder -> Expr -> Expr
Abs (Binder -> Expr -> Expr) -> m Binder -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
binder m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (App Expr
v1 Expr
v2) = Expr -> Expr -> Expr
App (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v1 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Unused Expr
v) = Expr -> Expr
Unused (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (IfThenElse Expr
v1 Expr
v2 Expr
v3) = Expr -> Expr -> Expr -> Expr
IfThenElse (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v1 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v3 m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Case [Expr]
vs [CaseAlternative]
alts) = [Expr] -> [CaseAlternative] -> Expr
Case ([Expr] -> [CaseAlternative] -> Expr)
-> m [Expr] -> m ([CaseAlternative] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr) -> [Expr] -> m [Expr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) [Expr]
vs m ([CaseAlternative] -> Expr) -> m [CaseAlternative] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CaseAlternative -> m CaseAlternative)
-> [CaseAlternative] -> m [CaseAlternative]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CaseAlternative -> m CaseAlternative
handleCaseAlternative [CaseAlternative]
alts
  g' (TypedValue Bool
check Expr
v SourceType
ty) = Bool -> Expr -> SourceType -> Expr
TypedValue Bool
check (Expr -> SourceType -> Expr) -> m Expr -> m (SourceType -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') m (SourceType -> Expr) -> m SourceType -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceType -> m SourceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceType
ty
  g' (Let WhereProvenance
w [Declaration]
ds Expr
v) = WhereProvenance -> [Declaration] -> Expr -> Expr
Let WhereProvenance
w ([Declaration] -> Expr -> Expr)
-> m [Declaration] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f) [Declaration]
ds m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Do Maybe ModuleName
m [DoNotationElement]
es) = Maybe ModuleName -> [DoNotationElement] -> Expr
Do Maybe ModuleName
m ([DoNotationElement] -> Expr) -> m [DoNotationElement] -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es
  g' (Ado Maybe ModuleName
m [DoNotationElement]
es Expr
v) = Maybe ModuleName -> [DoNotationElement] -> Expr -> Expr
Ado Maybe ModuleName
m ([DoNotationElement] -> Expr -> Expr)
-> m [DoNotationElement] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (PositionedValue SourceSpan
pos [Comment]
com Expr
v) = SourceSpan -> [Comment] -> Expr -> Expr
PositionedValue SourceSpan
pos [Comment]
com (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' Expr
other = Expr -> m Expr
g Expr
other

  h' :: Binder -> m Binder
  h' :: Binder -> m Binder
h' (LiteralBinder SourceSpan
ss Literal Binder
l) = SourceSpan -> Literal Binder -> Binder
LiteralBinder SourceSpan
ss (Literal Binder -> Binder) -> m (Literal Binder) -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> Literal Binder -> m (Literal Binder)
forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM (Binder -> m Binder
h (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Binder -> m Binder
h') Literal Binder
l
  h' (ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor [Binder]
bs) = SourceSpan
-> Qualified (ProperName 'ConstructorName) -> [Binder] -> Binder
ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor ([Binder] -> Binder) -> m [Binder] -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) [Binder]
bs
  h' (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = Binder -> Binder -> Binder -> Binder
BinaryNoParensBinder (Binder -> Binder -> Binder -> Binder)
-> m Binder -> m (Binder -> Binder -> Binder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b1 m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') m (Binder -> Binder -> Binder) -> m Binder -> m (Binder -> Binder)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Binder -> m Binder
h Binder
b2 m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') m (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Binder -> m Binder
h Binder
b3 m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' (ParensInBinder Binder
b) = Binder -> Binder
ParensInBinder (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' (NamedBinder SourceSpan
ss Ident
name Binder
b) = SourceSpan -> Ident -> Binder -> Binder
NamedBinder SourceSpan
ss Ident
name (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' (PositionedBinder SourceSpan
pos [Comment]
com Binder
b) = SourceSpan -> [Comment] -> Binder -> Binder
PositionedBinder SourceSpan
pos [Comment]
com (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' (TypedBinder SourceType
t Binder
b) = SourceType -> Binder -> Binder
TypedBinder SourceType
t (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' Binder
other = Binder -> m Binder
h Binder
other

  handleCaseAlternative :: CaseAlternative -> m CaseAlternative
  handleCaseAlternative :: CaseAlternative -> m CaseAlternative
handleCaseAlternative (CaseAlternative [Binder]
bs [GuardedExpr]
val) =
    [Binder] -> [GuardedExpr] -> CaseAlternative
CaseAlternative
      ([Binder] -> [GuardedExpr] -> CaseAlternative)
-> m [Binder] -> m ([GuardedExpr] -> CaseAlternative)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) [Binder]
bs
      m ([GuardedExpr] -> CaseAlternative)
-> m [GuardedExpr] -> m CaseAlternative
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g)) [GuardedExpr]
val

  handleDoNotationElement :: DoNotationElement -> m DoNotationElement
  handleDoNotationElement :: DoNotationElement -> m DoNotationElement
handleDoNotationElement (DoNotationValue Expr
v) = Expr -> DoNotationElement
DoNotationValue (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) Expr
v
  handleDoNotationElement (DoNotationBind Binder
b Expr
v) = Binder -> Expr -> DoNotationElement
DoNotationBind (Binder -> Expr -> DoNotationElement)
-> m Binder -> m (Expr -> DoNotationElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b m (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) Expr
v
  handleDoNotationElement (DoNotationLet [Declaration]
ds) = [Declaration] -> DoNotationElement
DoNotationLet ([Declaration] -> DoNotationElement)
-> m [Declaration] -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' (Declaration -> m Declaration)
-> (Declaration -> m Declaration) -> Declaration -> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f) [Declaration]
ds
  handleDoNotationElement (PositionedDoNotationElement SourceSpan
pos [Comment]
com DoNotationElement
e) = SourceSpan -> [Comment] -> DoNotationElement -> DoNotationElement
PositionedDoNotationElement SourceSpan
pos [Comment]
com (DoNotationElement -> DoNotationElement)
-> m DoNotationElement -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DoNotationElement -> m DoNotationElement
handleDoNotationElement DoNotationElement
e

  handleGuard :: Guard -> m Guard
  handleGuard :: Guard -> m Guard
handleGuard (ConditionGuard Expr
e) = Expr -> Guard
ConditionGuard (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) Expr
e
  handleGuard (PatternGuard Binder
b Expr
e) = Binder -> Expr -> Guard
PatternGuard (Binder -> Expr -> Guard) -> m Binder -> m (Expr -> Guard)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' (Binder -> m Binder) -> (Binder -> m Binder) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b m (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' (Expr -> m Expr) -> (Expr -> m Expr) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) Expr
e

everywhereOnValuesM
  :: forall m
   . (Monad m)
  => (Declaration -> m Declaration)
  -> (Expr -> m Expr)
  -> (Binder -> m Binder)
  -> ( Declaration -> m Declaration
     , Expr -> m Expr
     , Binder -> m Binder
     )
everywhereOnValuesM :: (Declaration -> m Declaration)
-> (Expr -> m Expr)
-> (Binder -> m Binder)
-> (Declaration -> m Declaration, Expr -> m Expr,
    Binder -> m Binder)
everywhereOnValuesM Declaration -> m Declaration
f Expr -> m Expr
g Binder -> m Binder
h = (Declaration -> m Declaration
f', Expr -> m Expr
g', Binder -> m Binder
h')
  where

  f' :: Declaration -> m Declaration
  f' :: Declaration -> m Declaration
f' (DataBindingGroupDeclaration NonEmpty Declaration
ds) = (NonEmpty Declaration -> Declaration
DataBindingGroupDeclaration (NonEmpty Declaration -> Declaration)
-> m (NonEmpty Declaration) -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration)
-> NonEmpty Declaration -> m (NonEmpty Declaration)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' NonEmpty Declaration
ds) m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (ValueDecl SourceAnn
sa Ident
name NameKind
nameKind [Binder]
bs [GuardedExpr]
val) =
    SourceAnn
-> Ident -> NameKind -> [Binder] -> [GuardedExpr] -> Declaration
ValueDecl SourceAnn
sa Ident
name NameKind
nameKind ([Binder] -> [GuardedExpr] -> Declaration)
-> m [Binder] -> m ([GuardedExpr] -> Declaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs m ([GuardedExpr] -> Declaration)
-> m [GuardedExpr] -> m Declaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard Expr -> m Expr
g') [GuardedExpr]
val m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = (NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration
BindingGroupDeclaration (NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
-> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (((SourceAnn, Ident), NameKind, Expr)
 -> m ((SourceAnn, Ident), NameKind, Expr))
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\((SourceAnn, Ident)
name, NameKind
nameKind, Expr
val) -> (,,) (SourceAnn, Ident)
name NameKind
nameKind (Expr -> ((SourceAnn, Ident), NameKind, Expr))
-> m Expr -> m ((SourceAnn, Ident), NameKind, Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
val) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (BoundValueDeclaration SourceAnn
sa Binder
b Expr
expr) = (SourceAnn -> Binder -> Expr -> Declaration
BoundValueDeclaration SourceAnn
sa (Binder -> Expr -> Declaration)
-> m Binder -> m (Expr -> Declaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b m (Expr -> Declaration) -> m Expr -> m Declaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
expr) m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps [Declaration]
ds) = (SourceAnn
-> ProperName 'ClassName
-> [(Text, Maybe SourceType)]
-> [SourceConstraint]
-> [FunctionalDependency]
-> [Declaration]
-> Declaration
TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps ([Declaration] -> Declaration) -> m [Declaration] -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' [Declaration]
ds) m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = (SourceAnn
-> [Ident]
-> Integer
-> Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args (TypeInstanceBody -> Declaration)
-> m TypeInstanceBody -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Declaration] -> m [Declaration])
-> TypeInstanceBody -> m TypeInstanceBody
forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody ((Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f') TypeInstanceBody
ds) m Declaration -> (Declaration -> m Declaration) -> m Declaration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' Declaration
other = Declaration -> m Declaration
f Declaration
other

  g' :: Expr -> m Expr
  g' :: Expr -> m Expr
g' (Literal SourceSpan
ss Literal Expr
l) = (SourceSpan -> Literal Expr -> Expr
Literal SourceSpan
ss (Literal Expr -> Expr) -> m (Literal Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr) -> Literal Expr -> m (Literal Expr)
forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM Expr -> m Expr
g' Literal Expr
l) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (UnaryMinus SourceSpan
ss Expr
v) = (SourceSpan -> Expr -> Expr
UnaryMinus SourceSpan
ss (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (BinaryNoParens Expr
op Expr
v1 Expr
v2) = (Expr -> Expr -> Expr -> Expr
BinaryNoParens (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
op m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v1 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Parens Expr
v) = (Expr -> Expr
Parens (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name Expr
v) = (Qualified (ProperName 'ClassName) -> Expr -> Expr
TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Accessor PSString
prop Expr
v) = (PSString -> Expr -> Expr
Accessor PSString
prop (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = (Expr -> [(PSString, Expr)] -> Expr
ObjectUpdate (Expr -> [(PSString, Expr)] -> Expr)
-> m Expr -> m ([(PSString, Expr)] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
obj m ([(PSString, Expr)] -> Expr) -> m [(PSString, Expr)] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((PSString, Expr) -> m (PSString, Expr))
-> [(PSString, Expr)] -> m [(PSString, Expr)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr -> m Expr) -> (PSString, Expr) -> m (PSString, Expr)
forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM Expr -> m Expr
g') [(PSString, Expr)]
vs) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (ObjectUpdateNested Expr
obj PathTree Expr
vs) = (Expr -> PathTree Expr -> Expr
ObjectUpdateNested (Expr -> PathTree Expr -> Expr)
-> m Expr -> m (PathTree Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
obj m (PathTree Expr -> Expr) -> m (PathTree Expr) -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr) -> PathTree Expr -> m (PathTree Expr)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr -> m Expr
g' PathTree Expr
vs) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Abs Binder
binder Expr
v) = (Binder -> Expr -> Expr
Abs (Binder -> Expr -> Expr) -> m Binder -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
binder m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (App Expr
v1 Expr
v2) = (Expr -> Expr -> Expr
App (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v1 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Unused Expr
v) = (Expr -> Expr
Unused (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (IfThenElse Expr
v1 Expr
v2 Expr
v3) = (Expr -> Expr -> Expr -> Expr
IfThenElse (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v1 m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v3) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Case [Expr]
vs [CaseAlternative]
alts) = ([Expr] -> [CaseAlternative] -> Expr
Case ([Expr] -> [CaseAlternative] -> Expr)
-> m [Expr] -> m ([CaseAlternative] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr) -> [Expr] -> m [Expr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr -> m Expr
g' [Expr]
vs m ([CaseAlternative] -> Expr) -> m [CaseAlternative] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CaseAlternative -> m CaseAlternative)
-> [CaseAlternative] -> m [CaseAlternative]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CaseAlternative -> m CaseAlternative
handleCaseAlternative [CaseAlternative]
alts) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (TypedValue Bool
check Expr
v SourceType
ty) = (Bool -> Expr -> SourceType -> Expr
TypedValue Bool
check (Expr -> SourceType -> Expr) -> m Expr -> m (SourceType -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v m (SourceType -> Expr) -> m SourceType -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceType -> m SourceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceType
ty) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Let WhereProvenance
w [Declaration]
ds Expr
v) = (WhereProvenance -> [Declaration] -> Expr -> Expr
Let WhereProvenance
w ([Declaration] -> Expr -> Expr)
-> m [Declaration] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' [Declaration]
ds m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Do Maybe ModuleName
m [DoNotationElement]
es) = (Maybe ModuleName -> [DoNotationElement] -> Expr
Do Maybe ModuleName
m ([DoNotationElement] -> Expr) -> m [DoNotationElement] -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Ado Maybe ModuleName
m [DoNotationElement]
es Expr
v) = (Maybe ModuleName -> [DoNotationElement] -> Expr -> Expr
Ado Maybe ModuleName
m ([DoNotationElement] -> Expr -> Expr)
-> m [DoNotationElement] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (PositionedValue SourceSpan
pos [Comment]
com Expr
v) = (SourceSpan -> [Comment] -> Expr -> Expr
PositionedValue SourceSpan
pos [Comment]
com (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) m Expr -> (Expr -> m Expr) -> m Expr
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' Expr
other = Expr -> m Expr
g Expr
other

  h' :: Binder -> m Binder
  h' :: Binder -> m Binder
h' (LiteralBinder SourceSpan
ss Literal Binder
l) = (SourceSpan -> Literal Binder -> Binder
LiteralBinder SourceSpan
ss (Literal Binder -> Binder) -> m (Literal Binder) -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> Literal Binder -> m (Literal Binder)
forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM Binder -> m Binder
h' Literal Binder
l) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor [Binder]
bs) = (SourceSpan
-> Qualified (ProperName 'ConstructorName) -> [Binder] -> Binder
ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor ([Binder] -> Binder) -> m [Binder] -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = (Binder -> Binder -> Binder -> Binder
BinaryNoParensBinder (Binder -> Binder -> Binder -> Binder)
-> m Binder -> m (Binder -> Binder -> Binder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b1 m (Binder -> Binder -> Binder) -> m Binder -> m (Binder -> Binder)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Binder -> m Binder
h' Binder
b2 m (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Binder -> m Binder
h' Binder
b3) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (ParensInBinder Binder
b) = (Binder -> Binder
ParensInBinder (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (NamedBinder SourceSpan
ss Ident
name Binder
b) = (SourceSpan -> Ident -> Binder -> Binder
NamedBinder SourceSpan
ss Ident
name (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (PositionedBinder SourceSpan
pos [Comment]
com Binder
b) = (SourceSpan -> [Comment] -> Binder -> Binder
PositionedBinder SourceSpan
pos [Comment]
com (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (TypedBinder SourceType
t Binder
b) = (SourceType -> Binder -> Binder
TypedBinder SourceType
t (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) m Binder -> (Binder -> m Binder) -> m Binder
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' Binder
other = Binder -> m Binder
h Binder
other

  handleCaseAlternative :: CaseAlternative -> m CaseAlternative
  handleCaseAlternative :: CaseAlternative -> m CaseAlternative
handleCaseAlternative (CaseAlternative [Binder]
bs [GuardedExpr]
val) =
    [Binder] -> [GuardedExpr] -> CaseAlternative
CaseAlternative
      ([Binder] -> [GuardedExpr] -> CaseAlternative)
-> m [Binder] -> m ([GuardedExpr] -> CaseAlternative)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs
      m ([GuardedExpr] -> CaseAlternative)
-> m [GuardedExpr] -> m CaseAlternative
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard Expr -> m Expr
g') [GuardedExpr]
val

  handleDoNotationElement :: DoNotationElement -> m DoNotationElement
  handleDoNotationElement :: DoNotationElement -> m DoNotationElement
handleDoNotationElement (DoNotationValue Expr
v) = Expr -> DoNotationElement
DoNotationValue (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v
  handleDoNotationElement (DoNotationBind Binder
b Expr
v) = Binder -> Expr -> DoNotationElement
DoNotationBind (Binder -> Expr -> DoNotationElement)
-> m Binder -> m (Expr -> DoNotationElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b m (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v
  handleDoNotationElement (DoNotationLet [Declaration]
ds) = [Declaration] -> DoNotationElement
DoNotationLet ([Declaration] -> DoNotationElement)
-> m [Declaration] -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' [Declaration]
ds
  handleDoNotationElement (PositionedDoNotationElement SourceSpan
pos [Comment]
com DoNotationElement
e) = SourceSpan -> [Comment] -> DoNotationElement -> DoNotationElement
PositionedDoNotationElement SourceSpan
pos [Comment]
com (DoNotationElement -> DoNotationElement)
-> m DoNotationElement -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DoNotationElement -> m DoNotationElement
handleDoNotationElement DoNotationElement
e

  handleGuard :: Guard -> m Guard
  handleGuard :: Guard -> m Guard
handleGuard (ConditionGuard Expr
e) = Expr -> Guard
ConditionGuard (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
e
  handleGuard (PatternGuard Binder
b Expr
e) = Binder -> Expr -> Guard
PatternGuard (Binder -> Expr -> Guard) -> m Binder -> m (Expr -> Guard)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b m (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
e

everythingOnValues
  :: forall r
   . (r -> r -> r)
  -> (Declaration -> r)
  -> (Expr -> r)
  -> (Binder -> r)
  -> (CaseAlternative -> r)
  -> (DoNotationElement -> r)
  -> ( Declaration -> r
     , Expr -> r
     , Binder -> r
     , CaseAlternative -> r
     , DoNotationElement -> r
     )
everythingOnValues :: (r -> r -> r)
-> (Declaration -> r)
-> (Expr -> r)
-> (Binder -> r)
-> (CaseAlternative -> r)
-> (DoNotationElement -> r)
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
everythingOnValues r -> r -> r
(<>.) Declaration -> r
f Expr -> r
g Binder -> r
h CaseAlternative -> r
i DoNotationElement -> r
j = (Declaration -> r
f', Expr -> r
g', Binder -> r
h', CaseAlternative -> r
i', DoNotationElement -> r
j')
  where

  f' :: Declaration -> r
  f' :: Declaration -> r
f' d :: Declaration
d@(DataBindingGroupDeclaration NonEmpty Declaration
ds) = (r -> r -> r) -> r -> NonEmpty r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) ((Declaration -> r) -> NonEmpty Declaration -> NonEmpty r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' NonEmpty Declaration
ds)
  f' d :: Declaration
d@(ValueDeclaration ValueDeclarationData [GuardedExpr]
vd) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> r
h' (ValueDeclarationData [GuardedExpr] -> [Binder]
forall a. ValueDeclarationData a -> [Binder]
valdeclBinders ValueDeclarationData [GuardedExpr]
vd) [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ (GuardedExpr -> [r]) -> [GuardedExpr] -> [r]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
v) -> (Guard -> r) -> [Guard] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Guard -> r
k' [Guard]
grd [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ [Expr -> r
g' Expr
v]) (ValueDeclarationData [GuardedExpr] -> [GuardedExpr]
forall a. ValueDeclarationData a -> a
valdeclExpression ValueDeclarationData [GuardedExpr]
vd))
  f' d :: Declaration
d@(BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = (r -> r -> r) -> r -> NonEmpty r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) ((((SourceAnn, Ident), NameKind, Expr) -> r)
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> NonEmpty r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((SourceAnn, Ident)
_, NameKind
_, Expr
val) -> Expr -> r
g' Expr
val) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds)
  f' d :: Declaration
d@(TypeClassDeclaration SourceAnn
_ ProperName 'ClassName
_ [(Text, Maybe SourceType)]
_ [SourceConstraint]
_ [FunctionalDependency]
_ [Declaration]
ds) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' [Declaration]
ds)
  f' d :: Declaration
d@(TypeInstanceDeclaration SourceAnn
_ [Ident]
_ Integer
_ Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' [Declaration]
ds)
  f' d :: Declaration
d@(BoundValueDeclaration SourceAnn
_ Binder
b Expr
expr) = Declaration -> r
f Declaration
d r -> r -> r
<>. Binder -> r
h' Binder
b r -> r -> r
<>. Expr -> r
g' Expr
expr
  f' Declaration
d = Declaration -> r
f Declaration
d

  g' :: Expr -> r
  g' :: Expr -> r
g' v :: Expr
v@(Literal SourceSpan
_ Literal Expr
l) = r -> (Expr -> r) -> Literal Expr -> r
forall a. r -> (a -> r) -> Literal a -> r
lit (Expr -> r
g Expr
v) Expr -> r
g' Literal Expr
l
  g' v :: Expr
v@(UnaryMinus SourceSpan
_ Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(BinaryNoParens Expr
op Expr
v1 Expr
v2) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
op r -> r -> r
<>. Expr -> r
g' Expr
v1 r -> r -> r
<>. Expr -> r
g' Expr
v2
  g' v :: Expr
v@(Parens Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
_ Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(Accessor PSString
_ Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
obj) (((PSString, Expr) -> r) -> [(PSString, Expr)] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Expr -> r
g' (Expr -> r) -> ((PSString, Expr) -> Expr) -> (PSString, Expr) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, Expr) -> Expr
forall a b. (a, b) -> b
snd) [(PSString, Expr)]
vs)
  g' v :: Expr
v@(ObjectUpdateNested Expr
obj PathTree Expr
vs) = (r -> r -> r) -> r -> PathTree r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
obj) ((Expr -> r) -> PathTree Expr -> PathTree r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> r
g' PathTree Expr
vs)
  g' v :: Expr
v@(Abs Binder
b Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Binder -> r
h' Binder
b r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(App Expr
v1 Expr
v2) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1 r -> r -> r
<>. Expr -> r
g' Expr
v2
  g' v :: Expr
v@(Unused Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(IfThenElse Expr
v1 Expr
v2 Expr
v3) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1 r -> r -> r
<>. Expr -> r
g' Expr
v2 r -> r -> r
<>. Expr -> r
g' Expr
v3
  g' v :: Expr
v@(Case [Expr]
vs [CaseAlternative]
alts) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) ((r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) ((Expr -> r) -> [Expr] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> r
g' [Expr]
vs)) ((CaseAlternative -> r) -> [CaseAlternative] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CaseAlternative -> r
i' [CaseAlternative]
alts)
  g' v :: Expr
v@(TypedValue Bool
_ Expr
v1 SourceType
_) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(Let WhereProvenance
_ [Declaration]
ds Expr
v1) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' [Declaration]
ds) r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(Do Maybe ModuleName
_ [DoNotationElement]
es) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) ((DoNotationElement -> r) -> [DoNotationElement] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoNotationElement -> r
j' [DoNotationElement]
es)
  g' v :: Expr
v@(Ado Maybe ModuleName
_ [DoNotationElement]
es Expr
v1) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) ((DoNotationElement -> r) -> [DoNotationElement] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoNotationElement -> r
j' [DoNotationElement]
es) r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' v :: Expr
v@(PositionedValue SourceSpan
_ [Comment]
_ Expr
v1) = Expr -> r
g Expr
v r -> r -> r
<>. Expr -> r
g' Expr
v1
  g' Expr
v = Expr -> r
g Expr
v

  h' :: Binder -> r
  h' :: Binder -> r
h' b :: Binder
b@(LiteralBinder SourceSpan
_ Literal Binder
l) = r -> (Binder -> r) -> Literal Binder -> r
forall a. r -> (a -> r) -> Literal a -> r
lit (Binder -> r
h Binder
b) Binder -> r
h' Literal Binder
l
  h' b :: Binder
b@(ConstructorBinder SourceSpan
_ Qualified (ProperName 'ConstructorName)
_ [Binder]
bs) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Binder -> r
h Binder
b) ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> r
h' [Binder]
bs)
  h' b :: Binder
b@(BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = Binder -> r
h Binder
b r -> r -> r
<>. Binder -> r
h' Binder
b1 r -> r -> r
<>. Binder -> r
h' Binder
b2 r -> r -> r
<>. Binder -> r
h' Binder
b3
  h' b :: Binder
b@(ParensInBinder Binder
b1) = Binder -> r
h Binder
b r -> r -> r
<>. Binder -> r
h' Binder
b1
  h' b :: Binder
b@(NamedBinder SourceSpan
_ Ident
_ Binder
b1) = Binder -> r
h Binder
b r -> r -> r
<>. Binder -> r
h' Binder
b1
  h' b :: Binder
b@(PositionedBinder SourceSpan
_ [Comment]
_ Binder
b1) = Binder -> r
h Binder
b r -> r -> r
<>. Binder -> r
h' Binder
b1
  h' b :: Binder
b@(TypedBinder SourceType
_ Binder
b1) = Binder -> r
h Binder
b r -> r -> r
<>. Binder -> r
h' Binder
b1
  h' Binder
b = Binder -> r
h Binder
b

  lit :: r -> (a -> r) -> Literal a -> r
  lit :: r -> (a -> r) -> Literal a -> r
lit r
r a -> r
go (ArrayLiteral [a]
as) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r ((a -> r) -> [a] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> r
go [a]
as)
  lit r
r a -> r
go (ObjectLiteral [(PSString, a)]
as) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r (((PSString, a) -> r) -> [(PSString, a)] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> r
go (a -> r) -> ((PSString, a) -> a) -> (PSString, a) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, a) -> a
forall a b. (a, b) -> b
snd) [(PSString, a)]
as)
  lit r
r a -> r
_ Literal a
_ = r
r

  i' :: CaseAlternative -> r
  i' :: CaseAlternative -> r
i' ca :: CaseAlternative
ca@(CaseAlternative [Binder]
bs [GuardedExpr]
gs) =
    (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (CaseAlternative -> r
i CaseAlternative
ca) ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> r
h' [Binder]
bs [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ (GuardedExpr -> [r]) -> [GuardedExpr] -> [r]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
val) -> (Guard -> r) -> [Guard] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Guard -> r
k' [Guard]
grd [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ [Expr -> r
g' Expr
val]) [GuardedExpr]
gs)

  j' :: DoNotationElement -> r
  j' :: DoNotationElement -> r
j' e :: DoNotationElement
e@(DoNotationValue Expr
v) = DoNotationElement -> r
j DoNotationElement
e r -> r -> r
<>. Expr -> r
g' Expr
v
  j' e :: DoNotationElement
e@(DoNotationBind Binder
b Expr
v) = DoNotationElement -> r
j DoNotationElement
e r -> r -> r
<>. Binder -> r
h' Binder
b r -> r -> r
<>. Expr -> r
g' Expr
v
  j' e :: DoNotationElement
e@(DoNotationLet [Declaration]
ds) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (DoNotationElement -> r
j DoNotationElement
e) ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' [Declaration]
ds)
  j' e :: DoNotationElement
e@(PositionedDoNotationElement SourceSpan
_ [Comment]
_ DoNotationElement
e1) = DoNotationElement -> r
j DoNotationElement
e r -> r -> r
<>. DoNotationElement -> r
j' DoNotationElement
e1

  k' :: Guard -> r
  k' :: Guard -> r
k' (ConditionGuard Expr
e) = Expr -> r
g' Expr
e
  k' (PatternGuard Binder
b Expr
e) = Binder -> r
h' Binder
b r -> r -> r
<>. Expr -> r
g' Expr
e

everythingWithContextOnValues
  :: forall s r
   . s
  -> r
  -> (r -> r -> r)
  -> (s -> Declaration       -> (s, r))
  -> (s -> Expr              -> (s, r))
  -> (s -> Binder            -> (s, r))
  -> (s -> CaseAlternative   -> (s, r))
  -> (s -> DoNotationElement -> (s, r))
  -> ( Declaration       -> r
     , Expr              -> r
     , Binder            -> r
     , CaseAlternative   -> r
     , DoNotationElement -> r)
everythingWithContextOnValues :: s
-> r
-> (r -> r -> r)
-> (s -> Declaration -> (s, r))
-> (s -> Expr -> (s, r))
-> (s -> Binder -> (s, r))
-> (s -> CaseAlternative -> (s, r))
-> (s -> DoNotationElement -> (s, r))
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
everythingWithContextOnValues s
s0 r
r0 r -> r -> r
(<>.) s -> Declaration -> (s, r)
f s -> Expr -> (s, r)
g s -> Binder -> (s, r)
h s -> CaseAlternative -> (s, r)
i s -> DoNotationElement -> (s, r)
j = (s -> Declaration -> r
f'' s
s0, s -> Expr -> r
g'' s
s0, s -> Binder -> r
h'' s
s0, s -> CaseAlternative -> r
i'' s
s0, s -> DoNotationElement -> r
j'' s
s0)
  where

  f'' :: s -> Declaration -> r
  f'' :: s -> Declaration -> r
f'' s
s Declaration
d = let (s
s', r
r) = s -> Declaration -> (s, r)
f s
s Declaration
d in r
r r -> r -> r
<>. s -> Declaration -> r
f' s
s' Declaration
d

  f' :: s -> Declaration -> r
  f' :: s -> Declaration -> r
f' s
s (DataBindingGroupDeclaration NonEmpty Declaration
ds) = (r -> r -> r) -> r -> NonEmpty r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Declaration -> r) -> NonEmpty Declaration -> NonEmpty r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Declaration -> r
f'' s
s) NonEmpty Declaration
ds)
  f' s
s (ValueDeclaration ValueDeclarationData [GuardedExpr]
vd) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Binder -> r
h'' s
s) (ValueDeclarationData [GuardedExpr] -> [Binder]
forall a. ValueDeclarationData a -> [Binder]
valdeclBinders ValueDeclarationData [GuardedExpr]
vd) [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ (GuardedExpr -> [r]) -> [GuardedExpr] -> [r]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
v) -> (Guard -> r) -> [Guard] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Guard -> r
k' s
s) [Guard]
grd [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ [s -> Expr -> r
g'' s
s Expr
v]) (ValueDeclarationData [GuardedExpr] -> [GuardedExpr]
forall a. ValueDeclarationData a -> a
valdeclExpression ValueDeclarationData [GuardedExpr]
vd))
  f' s
s (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = (r -> r -> r) -> r -> NonEmpty r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((((SourceAnn, Ident), NameKind, Expr) -> r)
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> NonEmpty r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((SourceAnn, Ident)
_, NameKind
_, Expr
val) -> s -> Expr -> r
g'' s
s Expr
val) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds)
  f' s
s (TypeClassDeclaration SourceAnn
_ ProperName 'ClassName
_ [(Text, Maybe SourceType)]
_ [SourceConstraint]
_ [FunctionalDependency]
_ [Declaration]
ds) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Declaration -> r
f'' s
s) [Declaration]
ds)
  f' s
s (TypeInstanceDeclaration SourceAnn
_ [Ident]
_ Integer
_ Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Declaration -> r
f'' s
s) [Declaration]
ds)
  f' s
_ Declaration
_ = r
r0

  g'' :: s -> Expr -> r
  g'' :: s -> Expr -> r
g'' s
s Expr
v = let (s
s', r
r) = s -> Expr -> (s, r)
g s
s Expr
v in r
r r -> r -> r
<>. s -> Expr -> r
g' s
s' Expr
v

  g' :: s -> Expr -> r
  g' :: s -> Expr -> r
g' s
s (Literal SourceSpan
_ Literal Expr
l) = (s -> Expr -> r) -> s -> Literal Expr -> r
forall a. (s -> a -> r) -> s -> Literal a -> r
lit s -> Expr -> r
g'' s
s Literal Expr
l
  g' s
s (UnaryMinus SourceSpan
_ Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (BinaryNoParens Expr
op Expr
v1 Expr
v2) = s -> Expr -> r
g'' s
s Expr
op r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v1 r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v2
  g' s
s (Parens Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
_ Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (Accessor PSString
_ Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (s -> Expr -> r
g'' s
s Expr
obj) (((PSString, Expr) -> r) -> [(PSString, Expr)] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Expr -> r
g'' s
s (Expr -> r) -> ((PSString, Expr) -> Expr) -> (PSString, Expr) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, Expr) -> Expr
forall a b. (a, b) -> b
snd) [(PSString, Expr)]
vs)
  g' s
s (ObjectUpdateNested Expr
obj PathTree Expr
vs) = (r -> r -> r) -> r -> PathTree r -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (s -> Expr -> r
g'' s
s Expr
obj) ((Expr -> r) -> PathTree Expr -> PathTree r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Expr -> r
g'' s
s) PathTree Expr
vs)
  g' s
s (Abs Binder
binder Expr
v1) = s -> Binder -> r
h'' s
s Binder
binder r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (App Expr
v1 Expr
v2) = s -> Expr -> r
g'' s
s Expr
v1 r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v2
  g' s
s (Unused Expr
v) = s -> Expr -> r
g'' s
s Expr
v
  g' s
s (IfThenElse Expr
v1 Expr
v2 Expr
v3) = s -> Expr -> r
g'' s
s Expr
v1 r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v2 r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v3
  g' s
s (Case [Expr]
vs [CaseAlternative]
alts) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) ((r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Expr -> r) -> [Expr] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Expr -> r
g'' s
s) [Expr]
vs)) ((CaseAlternative -> r) -> [CaseAlternative] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> CaseAlternative -> r
i'' s
s) [CaseAlternative]
alts)
  g' s
s (TypedValue Bool
_ Expr
v1 SourceType
_) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (Let WhereProvenance
_ [Declaration]
ds Expr
v1) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Declaration -> r
f'' s
s) [Declaration]
ds) r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (Do Maybe ModuleName
_ [DoNotationElement]
es) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((DoNotationElement -> r) -> [DoNotationElement] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> DoNotationElement -> r
j'' s
s) [DoNotationElement]
es)
  g' s
s (Ado Maybe ModuleName
_ [DoNotationElement]
es Expr
v1) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((DoNotationElement -> r) -> [DoNotationElement] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> DoNotationElement -> r
j'' s
s) [DoNotationElement]
es) r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (PositionedValue SourceSpan
_ [Comment]
_ Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
_ Expr
_ = r
r0

  h'' :: s -> Binder -> r
  h'' :: s -> Binder -> r
h'' s
s Binder
b = let (s
s', r
r) = s -> Binder -> (s, r)
h s
s Binder
b in r
r r -> r -> r
<>. s -> Binder -> r
h' s
s' Binder
b

  h' :: s -> Binder -> r
  h' :: s -> Binder -> r
h' s
s (LiteralBinder SourceSpan
_ Literal Binder
l) = (s -> Binder -> r) -> s -> Literal Binder -> r
forall a. (s -> a -> r) -> s -> Literal a -> r
lit s -> Binder -> r
h'' s
s Literal Binder
l
  h' s
s (ConstructorBinder SourceSpan
_ Qualified (ProperName 'ConstructorName)
_ [Binder]
bs) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Binder -> r
h'' s
s) [Binder]
bs)
  h' s
s (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = s -> Binder -> r
h'' s
s Binder
b1 r -> r -> r
<>. s -> Binder -> r
h'' s
s Binder
b2 r -> r -> r
<>. s -> Binder -> r
h'' s
s Binder
b3
  h' s
s (ParensInBinder Binder
b) = s -> Binder -> r
h'' s
s Binder
b
  h' s
s (NamedBinder SourceSpan
_ Ident
_ Binder
b1) = s -> Binder -> r
h'' s
s Binder
b1
  h' s
s (PositionedBinder SourceSpan
_ [Comment]
_ Binder
b1) = s -> Binder -> r
h'' s
s Binder
b1
  h' s
s (TypedBinder SourceType
_ Binder
b1) = s -> Binder -> r
h'' s
s Binder
b1
  h' s
_ Binder
_ = r
r0

  lit :: (s -> a -> r) -> s -> Literal a -> r
  lit :: (s -> a -> r) -> s -> Literal a -> r
lit s -> a -> r
go s
s (ArrayLiteral [a]
as) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((a -> r) -> [a] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> a -> r
go s
s) [a]
as)
  lit s -> a -> r
go s
s (ObjectLiteral [(PSString, a)]
as) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (((PSString, a) -> r) -> [(PSString, a)] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> a -> r
go s
s (a -> r) -> ((PSString, a) -> a) -> (PSString, a) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, a) -> a
forall a b. (a, b) -> b
snd) [(PSString, a)]
as)
  lit s -> a -> r
_ s
_ Literal a
_ = r
r0

  i'' :: s -> CaseAlternative -> r
  i'' :: s -> CaseAlternative -> r
i'' s
s CaseAlternative
ca = let (s
s', r
r) = s -> CaseAlternative -> (s, r)
i s
s CaseAlternative
ca in r
r r -> r -> r
<>. s -> CaseAlternative -> r
i' s
s' CaseAlternative
ca

  i' :: s -> CaseAlternative -> r
  i' :: s -> CaseAlternative -> r
i' s
s (CaseAlternative [Binder]
bs [GuardedExpr]
gs) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Binder -> r) -> [Binder] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Binder -> r
h'' s
s) [Binder]
bs [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ (GuardedExpr -> [r]) -> [GuardedExpr] -> [r]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
val) -> (Guard -> r) -> [Guard] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Guard -> r
k' s
s) [Guard]
grd [r] -> [r] -> [r]
forall a. [a] -> [a] -> [a]
++ [s -> Expr -> r
g'' s
s Expr
val]) [GuardedExpr]
gs)

  j'' :: s -> DoNotationElement -> r
  j'' :: s -> DoNotationElement -> r
j'' s
s DoNotationElement
e = let (s
s', r
r) = s -> DoNotationElement -> (s, r)
j s
s DoNotationElement
e in r
r r -> r -> r
<>. s -> DoNotationElement -> r
j' s
s' DoNotationElement
e

  j' :: s -> DoNotationElement -> r
  j' :: s -> DoNotationElement -> r
j' s
s (DoNotationValue Expr
v) = s -> Expr -> r
g'' s
s Expr
v
  j' s
s (DoNotationBind Binder
b Expr
v) = s -> Binder -> r
h'' s
s Binder
b r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
v
  j' s
s (DoNotationLet [Declaration]
ds) = (r -> r -> r) -> r -> [r] -> r
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 ((Declaration -> r) -> [Declaration] -> [r]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Declaration -> r
f'' s
s) [Declaration]
ds)
  j' s
s (PositionedDoNotationElement SourceSpan
_ [Comment]
_ DoNotationElement
e1) = s -> DoNotationElement -> r
j'' s
s DoNotationElement
e1

  k' :: s -> Guard -> r
  k' :: s -> Guard -> r
k' s
s (ConditionGuard Expr
e) = s -> Expr -> r
g'' s
s Expr
e
  k' s
s (PatternGuard Binder
b Expr
e) = s -> Binder -> r
h'' s
s Binder
b r -> r -> r
<>. s -> Expr -> r
g'' s
s Expr
e

everywhereWithContextOnValuesM
  :: forall m s
   . (Monad m)
  => s
  -> (s -> Declaration       -> m (s, Declaration))
  -> (s -> Expr              -> m (s, Expr))
  -> (s -> Binder            -> m (s, Binder))
  -> (s -> CaseAlternative   -> m (s, CaseAlternative))
  -> (s -> DoNotationElement -> m (s, DoNotationElement))
  -> ( Declaration       -> m Declaration
     , Expr              -> m Expr
     , Binder            -> m Binder
     , CaseAlternative   -> m CaseAlternative
     , DoNotationElement -> m DoNotationElement
     )
everywhereWithContextOnValuesM :: s
-> (s -> Declaration -> m (s, Declaration))
-> (s -> Expr -> m (s, Expr))
-> (s -> Binder -> m (s, Binder))
-> (s -> CaseAlternative -> m (s, CaseAlternative))
-> (s -> DoNotationElement -> m (s, DoNotationElement))
-> (Declaration -> m Declaration, Expr -> m Expr,
    Binder -> m Binder, CaseAlternative -> m CaseAlternative,
    DoNotationElement -> m DoNotationElement)
everywhereWithContextOnValuesM s
s0 s -> Declaration -> m (s, Declaration)
f s -> Expr -> m (s, Expr)
g s -> Binder -> m (s, Binder)
h s -> CaseAlternative -> m (s, CaseAlternative)
i s -> DoNotationElement -> m (s, DoNotationElement)
j = (s -> Declaration -> m Declaration
f'' s
s0, s -> Expr -> m Expr
g'' s
s0, s -> Binder -> m Binder
h'' s
s0, s -> CaseAlternative -> m CaseAlternative
i'' s
s0, s -> DoNotationElement -> m DoNotationElement
j'' s
s0)
  where
  f'' :: s -> Declaration -> m Declaration
f'' s
s = (s -> Declaration -> m Declaration)
-> (s, Declaration) -> m Declaration
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Declaration -> m Declaration
f' ((s, Declaration) -> m Declaration)
-> (Declaration -> m (s, Declaration))
-> Declaration
-> m Declaration
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> Declaration -> m (s, Declaration)
f s
s

  f' :: s -> Declaration -> m Declaration
f' s
s (DataBindingGroupDeclaration NonEmpty Declaration
ds) = NonEmpty Declaration -> Declaration
DataBindingGroupDeclaration (NonEmpty Declaration -> Declaration)
-> m (NonEmpty Declaration) -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration)
-> NonEmpty Declaration -> m (NonEmpty Declaration)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Declaration -> m Declaration
f'' s
s) NonEmpty Declaration
ds
  f' s
s (ValueDecl SourceAnn
sa Ident
name NameKind
nameKind [Binder]
bs [GuardedExpr]
val) =
    SourceAnn
-> Ident -> NameKind -> [Binder] -> [GuardedExpr] -> Declaration
ValueDecl SourceAnn
sa Ident
name NameKind
nameKind ([Binder] -> [GuardedExpr] -> Declaration)
-> m [Binder] -> m ([GuardedExpr] -> Declaration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Binder -> m Binder
h'' s
s) [Binder]
bs m ([GuardedExpr] -> Declaration)
-> m [GuardedExpr] -> m Declaration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM (s -> Guard -> m Guard
k' s
s) (s -> Expr -> m Expr
g'' s
s)) [GuardedExpr]
val
  f' s
s (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration
BindingGroupDeclaration (NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> Declaration)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
-> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (((SourceAnn, Ident), NameKind, Expr)
 -> m ((SourceAnn, Ident), NameKind, Expr))
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
-> m (NonEmpty ((SourceAnn, Ident), NameKind, Expr))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr -> m Expr)
-> ((SourceAnn, Ident), NameKind, Expr)
-> m ((SourceAnn, Ident), NameKind, Expr)
forall (f :: * -> *) c d a b.
Functor f =>
(c -> f d) -> (a, b, c) -> f (a, b, d)
thirdM (s -> Expr -> m Expr
g'' s
s)) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds
  f' s
s (TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps [Declaration]
ds) = SourceAnn
-> ProperName 'ClassName
-> [(Text, Maybe SourceType)]
-> [SourceConstraint]
-> [FunctionalDependency]
-> [Declaration]
-> Declaration
TypeClassDeclaration SourceAnn
sa ProperName 'ClassName
name [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
deps ([Declaration] -> Declaration) -> m [Declaration] -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Declaration -> m Declaration
f'' s
s) [Declaration]
ds
  f' s
s (TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = SourceAnn
-> [Ident]
-> Integer
-> Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa [Ident]
ch Integer
idx Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args (TypeInstanceBody -> Declaration)
-> m TypeInstanceBody -> m Declaration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Declaration] -> m [Declaration])
-> TypeInstanceBody -> m TypeInstanceBody
forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody ((Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Declaration -> m Declaration
f'' s
s)) TypeInstanceBody
ds
  f' s
_ Declaration
other = Declaration -> m Declaration
forall (m :: * -> *) a. Monad m => a -> m a
return Declaration
other

  g'' :: s -> Expr -> m Expr
g'' s
s = (s -> Expr -> m Expr) -> (s, Expr) -> m Expr
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Expr -> m Expr
g' ((s, Expr) -> m Expr) -> (Expr -> m (s, Expr)) -> Expr -> m Expr
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> Expr -> m (s, Expr)
g s
s

  g' :: s -> Expr -> m Expr
g' s
s (Literal SourceSpan
ss Literal Expr
l) = SourceSpan -> Literal Expr -> Expr
Literal SourceSpan
ss (Literal Expr -> Expr) -> m (Literal Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (s -> Expr -> m Expr) -> s -> Literal Expr -> m (Literal Expr)
forall a. (s -> a -> m a) -> s -> Literal a -> m (Literal a)
lit s -> Expr -> m Expr
g'' s
s Literal Expr
l
  g' s
s (UnaryMinus SourceSpan
ss Expr
v) = SourceSpan -> Expr -> Expr
UnaryMinus SourceSpan
ss (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (BinaryNoParens Expr
op Expr
v1 Expr
v2) = Expr -> Expr -> Expr -> Expr
BinaryNoParens (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
op m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v1 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v2
  g' s
s (Parens Expr
v) = Expr -> Expr
Parens (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name Expr
v) = Qualified (ProperName 'ClassName) -> Expr -> Expr
TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
name (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (Accessor PSString
prop Expr
v) = PSString -> Expr -> Expr
Accessor PSString
prop (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = Expr -> [(PSString, Expr)] -> Expr
ObjectUpdate (Expr -> [(PSString, Expr)] -> Expr)
-> m Expr -> m ([(PSString, Expr)] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
obj m ([(PSString, Expr)] -> Expr) -> m [(PSString, Expr)] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((PSString, Expr) -> m (PSString, Expr))
-> [(PSString, Expr)] -> m [(PSString, Expr)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr -> m Expr) -> (PSString, Expr) -> m (PSString, Expr)
forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM (s -> Expr -> m Expr
g'' s
s)) [(PSString, Expr)]
vs
  g' s
s (ObjectUpdateNested Expr
obj PathTree Expr
vs) = Expr -> PathTree Expr -> Expr
ObjectUpdateNested (Expr -> PathTree Expr -> Expr)
-> m Expr -> m (PathTree Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
obj m (PathTree Expr -> Expr) -> m (PathTree Expr) -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr) -> PathTree Expr -> m (PathTree Expr)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Expr -> m Expr
g'' s
s) PathTree Expr
vs
  g' s
s (Abs Binder
binder Expr
v) = Binder -> Expr -> Expr
Abs (Binder -> Expr -> Expr) -> m Binder -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h' s
s Binder
binder m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (App Expr
v1 Expr
v2) = Expr -> Expr -> Expr
App (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v1 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v2
  g' s
s (Unused Expr
v) = Expr -> Expr
Unused (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (IfThenElse Expr
v1 Expr
v2 Expr
v3) = Expr -> Expr -> Expr -> Expr
IfThenElse (Expr -> Expr -> Expr -> Expr)
-> m Expr -> m (Expr -> Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v1 m (Expr -> Expr -> Expr) -> m Expr -> m (Expr -> Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v2 m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v3
  g' s
s (Case [Expr]
vs [CaseAlternative]
alts) = [Expr] -> [CaseAlternative] -> Expr
Case ([Expr] -> [CaseAlternative] -> Expr)
-> m [Expr] -> m ([CaseAlternative] -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr) -> [Expr] -> m [Expr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Expr -> m Expr
g'' s
s) [Expr]
vs m ([CaseAlternative] -> Expr) -> m [CaseAlternative] -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CaseAlternative -> m CaseAlternative)
-> [CaseAlternative] -> m [CaseAlternative]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> CaseAlternative -> m CaseAlternative
i'' s
s) [CaseAlternative]
alts
  g' s
s (TypedValue Bool
check Expr
v SourceType
ty) = Bool -> Expr -> SourceType -> Expr
TypedValue Bool
check (Expr -> SourceType -> Expr) -> m Expr -> m (SourceType -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v m (SourceType -> Expr) -> m SourceType -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceType -> m SourceType
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceType
ty
  g' s
s (Let WhereProvenance
w [Declaration]
ds Expr
v) = WhereProvenance -> [Declaration] -> Expr -> Expr
Let WhereProvenance
w ([Declaration] -> Expr -> Expr)
-> m [Declaration] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Declaration -> m Declaration
f'' s
s) [Declaration]
ds m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (Do Maybe ModuleName
m [DoNotationElement]
es) = Maybe ModuleName -> [DoNotationElement] -> Expr
Do Maybe ModuleName
m ([DoNotationElement] -> Expr) -> m [DoNotationElement] -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> DoNotationElement -> m DoNotationElement
j'' s
s) [DoNotationElement]
es
  g' s
s (Ado Maybe ModuleName
m [DoNotationElement]
es Expr
v) = Maybe ModuleName -> [DoNotationElement] -> Expr -> Expr
Ado Maybe ModuleName
m ([DoNotationElement] -> Expr -> Expr)
-> m [DoNotationElement] -> m (Expr -> Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DoNotationElement -> m DoNotationElement)
-> [DoNotationElement] -> m [DoNotationElement]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> DoNotationElement -> m DoNotationElement
j'' s
s) [DoNotationElement]
es m (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
s (PositionedValue SourceSpan
pos [Comment]
com Expr
v) = SourceSpan -> [Comment] -> Expr -> Expr
PositionedValue SourceSpan
pos [Comment]
com (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  g' s
_ Expr
other = Expr -> m Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
other

  h'' :: s -> Binder -> m Binder
h'' s
s = (s -> Binder -> m Binder) -> (s, Binder) -> m Binder
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Binder -> m Binder
h' ((s, Binder) -> m Binder)
-> (Binder -> m (s, Binder)) -> Binder -> m Binder
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> Binder -> m (s, Binder)
h s
s

  h' :: s -> Binder -> m Binder
h' s
s (LiteralBinder SourceSpan
ss Literal Binder
l) = SourceSpan -> Literal Binder -> Binder
LiteralBinder SourceSpan
ss (Literal Binder -> Binder) -> m (Literal Binder) -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (s -> Binder -> m Binder)
-> s -> Literal Binder -> m (Literal Binder)
forall a. (s -> a -> m a) -> s -> Literal a -> m (Literal a)
lit s -> Binder -> m Binder
h'' s
s Literal Binder
l
  h' s
s (ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor [Binder]
bs) = SourceSpan
-> Qualified (ProperName 'ConstructorName) -> [Binder] -> Binder
ConstructorBinder SourceSpan
ss Qualified (ProperName 'ConstructorName)
ctor ([Binder] -> Binder) -> m [Binder] -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Binder -> m Binder
h'' s
s) [Binder]
bs
  h' s
s (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = Binder -> Binder -> Binder -> Binder
BinaryNoParensBinder (Binder -> Binder -> Binder -> Binder)
-> m Binder -> m (Binder -> Binder -> Binder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b1 m (Binder -> Binder -> Binder) -> m Binder -> m (Binder -> Binder)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Binder -> m Binder
h'' s
s Binder
b2 m (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Binder -> m Binder
h'' s
s Binder
b3
  h' s
s (ParensInBinder Binder
b) = Binder -> Binder
ParensInBinder (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b
  h' s
s (NamedBinder SourceSpan
ss Ident
name Binder
b) = SourceSpan -> Ident -> Binder -> Binder
NamedBinder SourceSpan
ss Ident
name (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b
  h' s
s (PositionedBinder SourceSpan
pos [Comment]
com Binder
b) = SourceSpan -> [Comment] -> Binder -> Binder
PositionedBinder SourceSpan
pos [Comment]
com (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b
  h' s
s (TypedBinder SourceType
t Binder
b) = SourceType -> Binder -> Binder
TypedBinder SourceType
t (Binder -> Binder) -> m Binder -> m Binder
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b
  h' s
_ Binder
other = Binder -> m Binder
forall (m :: * -> *) a. Monad m => a -> m a
return Binder
other

  lit :: (s -> a -> m a) -> s -> Literal a -> m (Literal a)
  lit :: (s -> a -> m a) -> s -> Literal a -> m (Literal a)
lit s -> a -> m a
go s
s (ArrayLiteral [a]
as) = [a] -> Literal a
forall a. [a] -> Literal a
ArrayLiteral ([a] -> Literal a) -> m [a] -> m (Literal a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> m a) -> [a] -> m [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> a -> m a
go s
s) [a]
as
  lit s -> a -> m a
go s
s (ObjectLiteral [(PSString, a)]
as) = [(PSString, a)] -> Literal a
forall a. [(PSString, a)] -> Literal a
ObjectLiteral ([(PSString, a)] -> Literal a)
-> m [(PSString, a)] -> m (Literal a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((PSString, a) -> m (PSString, a))
-> [(PSString, a)] -> m [(PSString, a)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((a -> m a) -> (PSString, a) -> m (PSString, a)
forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM (s -> a -> m a
go s
s)) [(PSString, a)]
as
  lit s -> a -> m a
_ s
_ Literal a
other = Literal a -> m (Literal a)
forall (m :: * -> *) a. Monad m => a -> m a
return Literal a
other

  i'' :: s -> CaseAlternative -> m CaseAlternative
i'' s
s = (s -> CaseAlternative -> m CaseAlternative)
-> (s, CaseAlternative) -> m CaseAlternative
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> CaseAlternative -> m CaseAlternative
i' ((s, CaseAlternative) -> m CaseAlternative)
-> (CaseAlternative -> m (s, CaseAlternative))
-> CaseAlternative
-> m CaseAlternative
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> CaseAlternative -> m (s, CaseAlternative)
i s
s

  i' :: s -> CaseAlternative -> m CaseAlternative
i' s
s (CaseAlternative [Binder]
bs [GuardedExpr]
val) = [Binder] -> [GuardedExpr] -> CaseAlternative
CaseAlternative ([Binder] -> [GuardedExpr] -> CaseAlternative)
-> m [Binder] -> m ([GuardedExpr] -> CaseAlternative)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder) -> [Binder] -> m [Binder]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Binder -> m Binder
h'' s
s) [Binder]
bs m ([GuardedExpr] -> CaseAlternative)
-> m [GuardedExpr] -> m CaseAlternative
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GuardedExpr -> m GuardedExpr) -> [GuardedExpr] -> m [GuardedExpr]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM (s -> Guard -> m Guard
k' s
s) (s -> Expr -> m Expr
g'' s
s)) [GuardedExpr]
val

  j'' :: s -> DoNotationElement -> m DoNotationElement
j'' s
s = (s -> DoNotationElement -> m DoNotationElement)
-> (s, DoNotationElement) -> m DoNotationElement
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> DoNotationElement -> m DoNotationElement
j' ((s, DoNotationElement) -> m DoNotationElement)
-> (DoNotationElement -> m (s, DoNotationElement))
-> DoNotationElement
-> m DoNotationElement
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> DoNotationElement -> m (s, DoNotationElement)
j s
s

  j' :: s -> DoNotationElement -> m DoNotationElement
j' s
s (DoNotationValue Expr
v) = Expr -> DoNotationElement
DoNotationValue (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v
  j' s
s (DoNotationBind Binder
b Expr
v) = Binder -> Expr -> DoNotationElement
DoNotationBind (Binder -> Expr -> DoNotationElement)
-> m Binder -> m (Expr -> DoNotationElement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b m (Expr -> DoNotationElement) -> m Expr -> m DoNotationElement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v
  j' s
s (DoNotationLet [Declaration]
ds) = [Declaration] -> DoNotationElement
DoNotationLet ([Declaration] -> DoNotationElement)
-> m [Declaration] -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Declaration -> m Declaration) -> [Declaration] -> m [Declaration]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> Declaration -> m Declaration
f'' s
s) [Declaration]
ds
  j' s
s (PositionedDoNotationElement SourceSpan
pos [Comment]
com DoNotationElement
e1) = SourceSpan -> [Comment] -> DoNotationElement -> DoNotationElement
PositionedDoNotationElement SourceSpan
pos [Comment]
com (DoNotationElement -> DoNotationElement)
-> m DoNotationElement -> m DoNotationElement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> DoNotationElement -> m DoNotationElement
j'' s
s DoNotationElement
e1

  k' :: s -> Guard -> m Guard
k' s
s (ConditionGuard Expr
e) = Expr -> Guard
ConditionGuard (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
e
  k' s
s (PatternGuard Binder
b Expr
e) = Binder -> Expr -> Guard
PatternGuard (Binder -> Expr -> Guard) -> m Binder -> m (Expr -> Guard)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b m (Expr -> Guard) -> m Expr -> m Guard
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
e

data ScopedIdent = LocalIdent Ident | ToplevelIdent Ident
  deriving (Int -> ScopedIdent -> ShowS
[ScopedIdent] -> ShowS
ScopedIdent -> String
(Int -> ScopedIdent -> ShowS)
-> (ScopedIdent -> String)
-> ([ScopedIdent] -> ShowS)
-> Show ScopedIdent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScopedIdent] -> ShowS
$cshowList :: [ScopedIdent] -> ShowS
show :: ScopedIdent -> String
$cshow :: ScopedIdent -> String
showsPrec :: Int -> ScopedIdent -> ShowS
$cshowsPrec :: Int -> ScopedIdent -> ShowS
Show, ScopedIdent -> ScopedIdent -> Bool
(ScopedIdent -> ScopedIdent -> Bool)
-> (ScopedIdent -> ScopedIdent -> Bool) -> Eq ScopedIdent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScopedIdent -> ScopedIdent -> Bool
$c/= :: ScopedIdent -> ScopedIdent -> Bool
== :: ScopedIdent -> ScopedIdent -> Bool
$c== :: ScopedIdent -> ScopedIdent -> Bool
Eq, Eq ScopedIdent
Eq ScopedIdent
-> (ScopedIdent -> ScopedIdent -> Ordering)
-> (ScopedIdent -> ScopedIdent -> Bool)
-> (ScopedIdent -> ScopedIdent -> Bool)
-> (ScopedIdent -> ScopedIdent -> Bool)
-> (ScopedIdent -> ScopedIdent -> Bool)
-> (ScopedIdent -> ScopedIdent -> ScopedIdent)
-> (ScopedIdent -> ScopedIdent -> ScopedIdent)
-> Ord ScopedIdent
ScopedIdent -> ScopedIdent -> Bool
ScopedIdent -> ScopedIdent -> Ordering
ScopedIdent -> ScopedIdent -> ScopedIdent
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ScopedIdent -> ScopedIdent -> ScopedIdent
$cmin :: ScopedIdent -> ScopedIdent -> ScopedIdent
max :: ScopedIdent -> ScopedIdent -> ScopedIdent
$cmax :: ScopedIdent -> ScopedIdent -> ScopedIdent
>= :: ScopedIdent -> ScopedIdent -> Bool
$c>= :: ScopedIdent -> ScopedIdent -> Bool
> :: ScopedIdent -> ScopedIdent -> Bool
$c> :: ScopedIdent -> ScopedIdent -> Bool
<= :: ScopedIdent -> ScopedIdent -> Bool
$c<= :: ScopedIdent -> ScopedIdent -> Bool
< :: ScopedIdent -> ScopedIdent -> Bool
$c< :: ScopedIdent -> ScopedIdent -> Bool
compare :: ScopedIdent -> ScopedIdent -> Ordering
$ccompare :: ScopedIdent -> ScopedIdent -> Ordering
$cp1Ord :: Eq ScopedIdent
Ord)

inScope :: Ident -> S.Set ScopedIdent -> Bool
inScope :: Ident -> Set ScopedIdent -> Bool
inScope Ident
i Set ScopedIdent
s = (Ident -> ScopedIdent
LocalIdent Ident
i ScopedIdent -> Set ScopedIdent -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set ScopedIdent
s) Bool -> Bool -> Bool
|| (Ident -> ScopedIdent
ToplevelIdent Ident
i ScopedIdent -> Set ScopedIdent -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set ScopedIdent
s)

everythingWithScope
  :: forall r
   . (Monoid r)
  => (S.Set ScopedIdent -> Declaration -> r)
  -> (S.Set ScopedIdent -> Expr -> r)
  -> (S.Set ScopedIdent -> Binder -> r)
  -> (S.Set ScopedIdent -> CaseAlternative -> r)
  -> (S.Set ScopedIdent -> DoNotationElement -> r)
  -> ( S.Set ScopedIdent -> Declaration -> r
     , S.Set ScopedIdent -> Expr -> r
     , S.Set ScopedIdent -> Binder -> r
     , S.Set ScopedIdent -> CaseAlternative -> r
     , S.Set ScopedIdent -> DoNotationElement -> r
     )
everythingWithScope :: (Set ScopedIdent -> Declaration -> r)
-> (Set ScopedIdent -> Expr -> r)
-> (Set ScopedIdent -> Binder -> r)
-> (Set ScopedIdent -> CaseAlternative -> r)
-> (Set ScopedIdent -> DoNotationElement -> r)
-> (Set ScopedIdent -> Declaration -> r,
    Set ScopedIdent -> Expr -> r, Set ScopedIdent -> Binder -> r,
    Set ScopedIdent -> CaseAlternative -> r,
    Set ScopedIdent -> DoNotationElement -> r)
everythingWithScope Set ScopedIdent -> Declaration -> r
f Set ScopedIdent -> Expr -> r
g Set ScopedIdent -> Binder -> r
h Set ScopedIdent -> CaseAlternative -> r
i Set ScopedIdent -> DoNotationElement -> r
j = (Set ScopedIdent -> Declaration -> r
f'', Set ScopedIdent -> Expr -> r
g'', Set ScopedIdent -> Binder -> r
h'', Set ScopedIdent -> CaseAlternative -> r
i'', \Set ScopedIdent
s -> (Set ScopedIdent, r) -> r
forall a b. (a, b) -> b
snd ((Set ScopedIdent, r) -> r)
-> (DoNotationElement -> (Set ScopedIdent, r))
-> DoNotationElement
-> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s)
  where
  f'' :: S.Set ScopedIdent -> Declaration -> r
  f'' :: Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s Declaration
a = Set ScopedIdent -> Declaration -> r
f Set ScopedIdent
s Declaration
a r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Declaration -> r
f' Set ScopedIdent
s Declaration
a

  f' :: S.Set ScopedIdent -> Declaration -> r
  f' :: Set ScopedIdent -> Declaration -> r
f' Set ScopedIdent
s (DataBindingGroupDeclaration NonEmpty Declaration
ds) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList ((Ident -> ScopedIdent) -> [Ident] -> [ScopedIdent]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
ToplevelIdent ((Declaration -> Maybe Ident) -> [Declaration] -> [Ident]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent (NonEmpty Declaration -> [Declaration]
forall a. NonEmpty a -> [a]
NEL.toList NonEmpty Declaration
ds))))
    in (Declaration -> r) -> NonEmpty Declaration -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s') NonEmpty Declaration
ds
  f' Set ScopedIdent
s (ValueDecl SourceAnn
_ Ident
name NameKind
_ [Binder]
bs [GuardedExpr]
val) =
    let s' :: Set ScopedIdent
s' = ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => a -> Set a -> Set a
S.insert (Ident -> ScopedIdent
ToplevelIdent Ident
name) Set ScopedIdent
s
        s'' :: Set ScopedIdent
s'' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s' ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList ((Binder -> [ScopedIdent]) -> [Binder] -> [ScopedIdent]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Binder -> [ScopedIdent]
localBinderNames [Binder]
bs))
    in (Binder -> r) -> [Binder] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s') [Binder]
bs r -> r -> r
forall a. Semigroup a => a -> a -> a
<> (GuardedExpr -> r) -> [GuardedExpr] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> GuardedExpr -> r
l' Set ScopedIdent
s'') [GuardedExpr]
val
  f' Set ScopedIdent
s (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList (NonEmpty ScopedIdent -> [ScopedIdent]
forall a. NonEmpty a -> [a]
NEL.toList ((((SourceAnn, Ident), NameKind, Expr) -> ScopedIdent)
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr)
-> NonEmpty ScopedIdent
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((SourceAnn
_, Ident
name), NameKind
_, Expr
_) -> Ident -> ScopedIdent
ToplevelIdent Ident
name) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds)))
    in (((SourceAnn, Ident), NameKind, Expr) -> r)
-> NonEmpty ((SourceAnn, Ident), NameKind, Expr) -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\((SourceAnn, Ident)
_, NameKind
_, Expr
val) -> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s' Expr
val) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds
  f' Set ScopedIdent
s (TypeClassDeclaration SourceAnn
_ ProperName 'ClassName
_ [(Text, Maybe SourceType)]
_ [SourceConstraint]
_ [FunctionalDependency]
_ [Declaration]
ds) = (Declaration -> r) -> [Declaration] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s) [Declaration]
ds
  f' Set ScopedIdent
s (TypeInstanceDeclaration SourceAnn
_ [Ident]
_ Integer
_ Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = (Declaration -> r) -> [Declaration] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s) [Declaration]
ds
  f' Set ScopedIdent
_ Declaration
_ = r
forall a. Monoid a => a
mempty

  g'' :: S.Set ScopedIdent -> Expr -> r
  g'' :: Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
a = Set ScopedIdent -> Expr -> r
g Set ScopedIdent
s Expr
a r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g' Set ScopedIdent
s Expr
a

  g' :: S.Set ScopedIdent -> Expr -> r
  g' :: Set ScopedIdent -> Expr -> r
g' Set ScopedIdent
s (Literal SourceSpan
_ Literal Expr
l) = (Set ScopedIdent -> Expr -> r)
-> Set ScopedIdent -> Literal Expr -> r
forall a.
(Set ScopedIdent -> a -> r) -> Set ScopedIdent -> Literal a -> r
lit Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Literal Expr
l
  g' Set ScopedIdent
s (UnaryMinus SourceSpan
_ Expr
v1) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
s (BinaryNoParens Expr
op Expr
v1 Expr
v2) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
op r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1 r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v2
  g' Set ScopedIdent
s (Parens Expr
v1) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
s (TypeClassDictionaryConstructorApp Qualified (ProperName 'ClassName)
_ Expr
v1) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
s (Accessor PSString
_ Expr
v1) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
s (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
obj r -> r -> r
forall a. Semigroup a => a -> a -> a
<> ((PSString, Expr) -> r) -> [(PSString, Expr)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s (Expr -> r) -> ((PSString, Expr) -> Expr) -> (PSString, Expr) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, Expr) -> Expr
forall a b. (a, b) -> b
snd) [(PSString, Expr)]
vs
  g' Set ScopedIdent
s (ObjectUpdateNested Expr
obj PathTree Expr
vs) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
obj r -> r -> r
forall a. Semigroup a => a -> a -> a
<> (Expr -> r) -> PathTree Expr -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s) PathTree Expr
vs
  g' Set ScopedIdent
s (Abs Binder
b Expr
v1) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList (Binder -> [ScopedIdent]
localBinderNames Binder
b)) Set ScopedIdent
s
    in Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s' Expr
v1
  g' Set ScopedIdent
s (App Expr
v1 Expr
v2) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1 r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v2
  g' Set ScopedIdent
s (Unused Expr
v) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v
  g' Set ScopedIdent
s (IfThenElse Expr
v1 Expr
v2 Expr
v3) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1 r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v2 r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v3
  g' Set ScopedIdent
s (Case [Expr]
vs [CaseAlternative]
alts) = (Expr -> r) -> [Expr] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s) [Expr]
vs r -> r -> r
forall a. Semigroup a => a -> a -> a
<> (CaseAlternative -> r) -> [CaseAlternative] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> CaseAlternative -> r
i'' Set ScopedIdent
s) [CaseAlternative]
alts
  g' Set ScopedIdent
s (TypedValue Bool
_ Expr
v1 SourceType
_) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
s (Let WhereProvenance
_ [Declaration]
ds Expr
v1) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList ((Ident -> ScopedIdent) -> [Ident] -> [ScopedIdent]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent ((Declaration -> Maybe Ident) -> [Declaration] -> [Ident]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent [Declaration]
ds)))
    in (Declaration -> r) -> [Declaration] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s') [Declaration]
ds r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s' Expr
v1
  g' Set ScopedIdent
s (Do Maybe ModuleName
_ [DoNotationElement]
es) = [r] -> r
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold ([r] -> r)
-> ([DoNotationElement] -> [r]) -> [DoNotationElement] -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set ScopedIdent, [r]) -> [r]
forall a b. (a, b) -> b
snd ((Set ScopedIdent, [r]) -> [r])
-> ([DoNotationElement] -> (Set ScopedIdent, [r]))
-> [DoNotationElement]
-> [r]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r))
-> Set ScopedIdent -> [DoNotationElement] -> (Set ScopedIdent, [r])
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> (a, c)) -> a -> t b -> (a, t c)
mapAccumL Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s ([DoNotationElement] -> r) -> [DoNotationElement] -> r
forall a b. (a -> b) -> a -> b
$ [DoNotationElement]
es
  g' Set ScopedIdent
s (Ado Maybe ModuleName
_ [DoNotationElement]
es Expr
v1) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ((DoNotationElement -> Set ScopedIdent)
-> [DoNotationElement] -> Set ScopedIdent
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((Set ScopedIdent, r) -> Set ScopedIdent
forall a b. (a, b) -> a
fst ((Set ScopedIdent, r) -> Set ScopedIdent)
-> (DoNotationElement -> (Set ScopedIdent, r))
-> DoNotationElement
-> Set ScopedIdent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s) [DoNotationElement]
es)
    in Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s' Expr
v1
  g' Set ScopedIdent
s (PositionedValue SourceSpan
_ [Comment]
_ Expr
v1) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1
  g' Set ScopedIdent
_ Expr
_ = r
forall a. Monoid a => a
mempty

  h'' :: S.Set ScopedIdent -> Binder -> r
  h'' :: Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
a = Set ScopedIdent -> Binder -> r
h Set ScopedIdent
s Binder
a r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Binder -> r
h' Set ScopedIdent
s Binder
a

  h' :: S.Set ScopedIdent -> Binder -> r
  h' :: Set ScopedIdent -> Binder -> r
h' Set ScopedIdent
s (LiteralBinder SourceSpan
_ Literal Binder
l) = (Set ScopedIdent -> Binder -> r)
-> Set ScopedIdent -> Literal Binder -> r
forall a.
(Set ScopedIdent -> a -> r) -> Set ScopedIdent -> Literal a -> r
lit Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Literal Binder
l
  h' Set ScopedIdent
s (ConstructorBinder SourceSpan
_ Qualified (ProperName 'ConstructorName)
_ [Binder]
bs) = (Binder -> r) -> [Binder] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s) [Binder]
bs
  h' Set ScopedIdent
s (BinaryNoParensBinder Binder
b1 Binder
b2 Binder
b3) = (Binder -> r) -> [Binder] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s) [Binder
b1, Binder
b2, Binder
b3]
  h' Set ScopedIdent
s (ParensInBinder Binder
b) = Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b
  h' Set ScopedIdent
s (NamedBinder SourceSpan
_ Ident
name Binder
b1) = Set ScopedIdent -> Binder -> r
h'' (ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => a -> Set a -> Set a
S.insert (Ident -> ScopedIdent
LocalIdent Ident
name) Set ScopedIdent
s) Binder
b1
  h' Set ScopedIdent
s (PositionedBinder SourceSpan
_ [Comment]
_ Binder
b1) = Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b1
  h' Set ScopedIdent
s (TypedBinder SourceType
_ Binder
b1) = Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b1
  h' Set ScopedIdent
_ Binder
_ = r
forall a. Monoid a => a
mempty

  lit :: (S.Set ScopedIdent -> a -> r) -> S.Set ScopedIdent -> Literal a -> r
  lit :: (Set ScopedIdent -> a -> r) -> Set ScopedIdent -> Literal a -> r
lit Set ScopedIdent -> a -> r
go Set ScopedIdent
s (ArrayLiteral [a]
as) = (a -> r) -> [a] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> a -> r
go Set ScopedIdent
s) [a]
as
  lit Set ScopedIdent -> a -> r
go Set ScopedIdent
s (ObjectLiteral [(PSString, a)]
as) = ((PSString, a) -> r) -> [(PSString, a)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> a -> r
go Set ScopedIdent
s (a -> r) -> ((PSString, a) -> a) -> (PSString, a) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSString, a) -> a
forall a b. (a, b) -> b
snd) [(PSString, a)]
as
  lit Set ScopedIdent -> a -> r
_ Set ScopedIdent
_ Literal a
_ = r
forall a. Monoid a => a
mempty

  i'' :: S.Set ScopedIdent -> CaseAlternative -> r
  i'' :: Set ScopedIdent -> CaseAlternative -> r
i'' Set ScopedIdent
s CaseAlternative
a = Set ScopedIdent -> CaseAlternative -> r
i Set ScopedIdent
s CaseAlternative
a r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> CaseAlternative -> r
i' Set ScopedIdent
s CaseAlternative
a

  i' :: S.Set ScopedIdent -> CaseAlternative -> r
  i' :: Set ScopedIdent -> CaseAlternative -> r
i' Set ScopedIdent
s (CaseAlternative [Binder]
bs [GuardedExpr]
gs) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList ((Binder -> [ScopedIdent]) -> [Binder] -> [ScopedIdent]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Binder -> [ScopedIdent]
localBinderNames [Binder]
bs))
    in (Binder -> r) -> [Binder] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s) [Binder]
bs r -> r -> r
forall a. Semigroup a => a -> a -> a
<> (GuardedExpr -> r) -> [GuardedExpr] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> GuardedExpr -> r
l' Set ScopedIdent
s') [GuardedExpr]
gs

  j'' :: S.Set ScopedIdent -> DoNotationElement -> (S.Set ScopedIdent, r)
  j'' :: Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s DoNotationElement
a = let (Set ScopedIdent
s', r
r) = Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j' Set ScopedIdent
s DoNotationElement
a in (Set ScopedIdent
s', Set ScopedIdent -> DoNotationElement -> r
j Set ScopedIdent
s DoNotationElement
a r -> r -> r
forall a. Semigroup a => a -> a -> a
<> r
r)

  j' :: S.Set ScopedIdent -> DoNotationElement -> (S.Set ScopedIdent, r)
  j' :: Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j' Set ScopedIdent
s (DoNotationValue Expr
v) = (Set ScopedIdent
s, Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v)
  j' Set ScopedIdent
s (DoNotationBind Binder
b Expr
v) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList (Binder -> [ScopedIdent]
localBinderNames Binder
b)) Set ScopedIdent
s
    in (Set ScopedIdent
s', Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v)
  j' Set ScopedIdent
s (DoNotationLet [Declaration]
ds) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList ((Ident -> ScopedIdent) -> [Ident] -> [ScopedIdent]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent ((Declaration -> Maybe Ident) -> [Declaration] -> [Ident]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent [Declaration]
ds)))
    in (Set ScopedIdent
s', (Declaration -> r) -> [Declaration] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s') [Declaration]
ds)
  j' Set ScopedIdent
s (PositionedDoNotationElement SourceSpan
_ [Comment]
_ DoNotationElement
e1) = Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s DoNotationElement
e1

  k' :: S.Set ScopedIdent -> Guard -> (S.Set ScopedIdent, r)
  k' :: Set ScopedIdent -> Guard -> (Set ScopedIdent, r)
k' Set ScopedIdent
s (ConditionGuard Expr
e) = (Set ScopedIdent
s, Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
e)
  k' Set ScopedIdent
s (PatternGuard Binder
b Expr
e) =
    let s' :: Set ScopedIdent
s' = Set ScopedIdent -> Set ScopedIdent -> Set ScopedIdent
forall a. Ord a => Set a -> Set a -> Set a
S.union ([ScopedIdent] -> Set ScopedIdent
forall a. Ord a => [a] -> Set a
S.fromList (Binder -> [ScopedIdent]
localBinderNames Binder
b)) Set ScopedIdent
s
    in (Set ScopedIdent
s', Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s Binder
b r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s' Expr
e)

  l' :: Set ScopedIdent -> GuardedExpr -> r
l' Set ScopedIdent
s (GuardedExpr [] Expr
e) = Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
e
  l' Set ScopedIdent
s (GuardedExpr (Guard
grd:[Guard]
gs) Expr
e) =
    let (Set ScopedIdent
s', r
r) = Set ScopedIdent -> Guard -> (Set ScopedIdent, r)
k' Set ScopedIdent
s Guard
grd
    in r
r r -> r -> r
forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> GuardedExpr -> r
l' Set ScopedIdent
s' ([Guard] -> Expr -> GuardedExpr
GuardedExpr [Guard]
gs Expr
e)

  getDeclIdent :: Declaration -> Maybe Ident
  getDeclIdent :: Declaration -> Maybe Ident
getDeclIdent (ValueDeclaration ValueDeclarationData [GuardedExpr]
vd) = Ident -> Maybe Ident
forall a. a -> Maybe a
Just (ValueDeclarationData [GuardedExpr] -> Ident
forall a. ValueDeclarationData a -> Ident
valdeclIdent ValueDeclarationData [GuardedExpr]
vd)
  getDeclIdent (TypeDeclaration TypeDeclarationData
td) = Ident -> Maybe Ident
forall a. a -> Maybe a
Just (TypeDeclarationData -> Ident
tydeclIdent TypeDeclarationData
td)
  getDeclIdent Declaration
_ = Maybe Ident
forall a. Maybe a
Nothing

  localBinderNames :: Binder -> [ScopedIdent]
localBinderNames = (Ident -> ScopedIdent) -> [Ident] -> [ScopedIdent]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent ([Ident] -> [ScopedIdent])
-> (Binder -> [Ident]) -> Binder -> [ScopedIdent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binder -> [Ident]
binderNames

accumTypes
  :: (Monoid r)
  => (SourceType -> r)
  -> ( Declaration -> r
     , Expr -> r
     , Binder -> r
     , CaseAlternative -> r
     , DoNotationElement -> r
     )
accumTypes :: (SourceType -> r)
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
accumTypes SourceType -> r
f = (r -> r -> r)
-> (Declaration -> r)
-> (Expr -> r)
-> (Binder -> r)
-> (CaseAlternative -> r)
-> (DoNotationElement -> r)
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
forall r.
(r -> r -> r)
-> (Declaration -> r)
-> (Expr -> r)
-> (Binder -> r)
-> (CaseAlternative -> r)
-> (DoNotationElement -> r)
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
everythingOnValues r -> r -> r
forall a. Monoid a => a -> a -> a
mappend Declaration -> r
forDecls Expr -> r
forValues Binder -> r
forBinders (r -> CaseAlternative -> r
forall a b. a -> b -> a
const r
forall a. Monoid a => a
mempty) (r -> DoNotationElement -> r
forall a b. a -> b -> a
const r
forall a. Monoid a => a
mempty)
  where
  forDecls :: Declaration -> r
forDecls (DataDeclaration SourceAnn
_ DataDeclType
_ ProperName 'TypeName
_ [(Text, Maybe SourceType)]
args [DataConstructorDeclaration]
dctors) =
    ((Text, Maybe SourceType) -> r) -> [(Text, Maybe SourceType)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((SourceType -> r) -> Maybe SourceType -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f (Maybe SourceType -> r)
-> ((Text, Maybe SourceType) -> Maybe SourceType)
-> (Text, Maybe SourceType)
-> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Maybe SourceType) -> Maybe SourceType
forall a b. (a, b) -> b
snd) [(Text, Maybe SourceType)]
args r -> r -> r
forall a. Semigroup a => a -> a -> a
<>
    (DataConstructorDeclaration -> r)
-> [DataConstructorDeclaration] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (((Ident, SourceType) -> r) -> [(Ident, SourceType)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (SourceType -> r
f (SourceType -> r)
-> ((Ident, SourceType) -> SourceType) -> (Ident, SourceType) -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ident, SourceType) -> SourceType
forall a b. (a, b) -> b
snd) ([(Ident, SourceType)] -> r)
-> (DataConstructorDeclaration -> [(Ident, SourceType)])
-> DataConstructorDeclaration
-> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataConstructorDeclaration -> [(Ident, SourceType)]
dataCtorFields) [DataConstructorDeclaration]
dctors
  forDecls (ExternDataDeclaration SourceAnn
_ ProperName 'TypeName
_ SourceType
ty) = SourceType -> r
f SourceType
ty
  forDecls (ExternDeclaration SourceAnn
_ Ident
_ SourceType
ty) = SourceType -> r
f SourceType
ty
  forDecls (TypeClassDeclaration SourceAnn
_ ProperName 'ClassName
_ [(Text, Maybe SourceType)]
args [SourceConstraint]
implies [FunctionalDependency]
_ [Declaration]
_) =
    ((Text, Maybe SourceType) -> r) -> [(Text, Maybe SourceType)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((Maybe SourceType -> r) -> (Text, Maybe SourceType) -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((SourceType -> r) -> Maybe SourceType -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f)) [(Text, Maybe SourceType)]
args r -> r -> r
forall a. Semigroup a => a -> a -> a
<>
    (SourceConstraint -> r) -> [SourceConstraint] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((SourceType -> r) -> [SourceType] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f ([SourceType] -> r)
-> (SourceConstraint -> [SourceType]) -> SourceConstraint -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceConstraint -> [SourceType]
forall a. Constraint a -> [Type a]
constraintArgs) [SourceConstraint]
implies
  forDecls (TypeInstanceDeclaration SourceAnn
_ [Ident]
_ Integer
_ Ident
_ [SourceConstraint]
cs Qualified (ProperName 'ClassName)
_ [SourceType]
tys TypeInstanceBody
_) =
    (SourceConstraint -> r) -> [SourceConstraint] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((SourceType -> r) -> [SourceType] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f ([SourceType] -> r)
-> (SourceConstraint -> [SourceType]) -> SourceConstraint -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceConstraint -> [SourceType]
forall a. Constraint a -> [Type a]
constraintArgs) [SourceConstraint]
cs r -> r -> r
forall a. Semigroup a => a -> a -> a
<> (SourceType -> r) -> [SourceType] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f [SourceType]
tys
  forDecls (TypeSynonymDeclaration SourceAnn
_ ProperName 'TypeName
_ [(Text, Maybe SourceType)]
args SourceType
ty) =
    ((Text, Maybe SourceType) -> r) -> [(Text, Maybe SourceType)] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((SourceType -> r) -> Maybe SourceType -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f (Maybe SourceType -> r)
-> ((Text, Maybe SourceType) -> Maybe SourceType)
-> (Text, Maybe SourceType)
-> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Maybe SourceType) -> Maybe SourceType
forall a b. (a, b) -> b
snd) [(Text, Maybe SourceType)]
args r -> r -> r
forall a. Semigroup a => a -> a -> a
<>
    SourceType -> r
f SourceType
ty
  forDecls (KindDeclaration SourceAnn
_ KindSignatureFor
_ ProperName 'TypeName
_ SourceType
ty) = SourceType -> r
f SourceType
ty
  forDecls (TypeDeclaration TypeDeclarationData
td) = SourceType -> r
f (TypeDeclarationData -> SourceType
tydeclType TypeDeclarationData
td)
  forDecls Declaration
_ = r
forall a. Monoid a => a
mempty

  forValues :: Expr -> r
forValues (TypeClassDictionary SourceConstraint
c Map
  (Maybe ModuleName)
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
_ [ErrorMessageHint]
_) = (SourceType -> r) -> [SourceType] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f (SourceConstraint -> [SourceType]
forall a. Constraint a -> [Type a]
constraintArgs SourceConstraint
c)
  forValues (DeferredDictionary Qualified (ProperName 'ClassName)
_ [SourceType]
tys) = (SourceType -> r) -> [SourceType] -> r
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f [SourceType]
tys
  forValues (TypedValue Bool
_ Expr
_ SourceType
ty) = SourceType -> r
f SourceType
ty
  forValues Expr
_ = r
forall a. Monoid a => a
mempty

  forBinders :: Binder -> r
forBinders (TypedBinder SourceType
ty Binder
_) = SourceType -> r
f SourceType
ty
  forBinders Binder
_ = r
forall a. Monoid a => a
mempty

-- |
-- Map a function over type annotations appearing inside a value
--
overTypes :: (SourceType -> SourceType) -> Expr -> Expr
overTypes :: (SourceType -> SourceType) -> Expr -> Expr
overTypes SourceType -> SourceType
f = let (Declaration -> Declaration
_, Expr -> Expr
f', Binder -> Binder
_) = (Declaration -> Declaration)
-> (Expr -> Expr)
-> (Binder -> Binder)
-> (Declaration -> Declaration, Expr -> Expr, Binder -> Binder)
everywhereOnValues Declaration -> Declaration
forall a. a -> a
id Expr -> Expr
g Binder -> Binder
forall a. a -> a
id in Expr -> Expr
f'
  where
  g :: Expr -> Expr
  g :: Expr -> Expr
g (TypedValue Bool
checkTy Expr
val SourceType
t) = Bool -> Expr -> SourceType -> Expr
TypedValue Bool
checkTy Expr
val (SourceType -> SourceType
f SourceType
t)
  g (TypeClassDictionary SourceConstraint
c Map
  (Maybe ModuleName)
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
sco [ErrorMessageHint]
hints) =
    SourceConstraint
-> Map
     (Maybe ModuleName)
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> [ErrorMessageHint]
-> Expr
TypeClassDictionary
      (([SourceType] -> [SourceType])
-> SourceConstraint -> SourceConstraint
forall a. ([Type a] -> [Type a]) -> Constraint a -> Constraint a
mapConstraintArgs ((SourceType -> SourceType) -> [SourceType] -> [SourceType]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourceType -> SourceType
f) SourceConstraint
c)
      (Map
  (Maybe ModuleName)
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Map
     (Maybe ModuleName)
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateCtx Map
  (Maybe ModuleName)
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
sco)
      [ErrorMessageHint]
hints
  g Expr
other = Expr
other
  updateDict :: ([SourceType] -> [SourceType])
-> TypeClassDictionaryInScope v -> TypeClassDictionaryInScope v
updateDict [SourceType] -> [SourceType]
fn TypeClassDictionaryInScope v
dict = TypeClassDictionaryInScope v
dict { tcdInstanceTypes :: [SourceType]
tcdInstanceTypes = [SourceType] -> [SourceType]
fn (TypeClassDictionaryInScope v -> [SourceType]
forall v. TypeClassDictionaryInScope v -> [SourceType]
tcdInstanceTypes TypeClassDictionaryInScope v
dict) }
  updateScope :: Maybe
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateScope = (Map
   (Qualified (ProperName 'ClassName))
   (Map (Qualified Ident) (NonEmpty NamedDict))
 -> Map
      (Qualified (ProperName 'ClassName))
      (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Map
    (Qualified (ProperName 'ClassName))
    (Map (Qualified Ident) (NonEmpty NamedDict))
  -> Map
       (Qualified (ProperName 'ClassName))
       (Map (Qualified Ident) (NonEmpty NamedDict)))
 -> Maybe
      (Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict)))
 -> Maybe
      (Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict))))
-> ((NamedDict -> NamedDict)
    -> Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict))
    -> Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict)))
-> (NamedDict -> NamedDict)
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Qualified Ident) (NonEmpty NamedDict)
 -> Map (Qualified Ident) (NonEmpty NamedDict))
-> Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict))
-> Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Map (Qualified Ident) (NonEmpty NamedDict)
  -> Map (Qualified Ident) (NonEmpty NamedDict))
 -> Map
      (Qualified (ProperName 'ClassName))
      (Map (Qualified Ident) (NonEmpty NamedDict))
 -> Map
      (Qualified (ProperName 'ClassName))
      (Map (Qualified Ident) (NonEmpty NamedDict)))
-> ((NamedDict -> NamedDict)
    -> Map (Qualified Ident) (NonEmpty NamedDict)
    -> Map (Qualified Ident) (NonEmpty NamedDict))
-> (NamedDict -> NamedDict)
-> Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict))
-> Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmpty NamedDict -> NonEmpty NamedDict)
-> Map (Qualified Ident) (NonEmpty NamedDict)
-> Map (Qualified Ident) (NonEmpty NamedDict)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((NonEmpty NamedDict -> NonEmpty NamedDict)
 -> Map (Qualified Ident) (NonEmpty NamedDict)
 -> Map (Qualified Ident) (NonEmpty NamedDict))
-> ((NamedDict -> NamedDict)
    -> NonEmpty NamedDict -> NonEmpty NamedDict)
-> (NamedDict -> NamedDict)
-> Map (Qualified Ident) (NonEmpty NamedDict)
-> Map (Qualified Ident) (NonEmpty NamedDict)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NamedDict -> NamedDict)
-> NonEmpty NamedDict -> NonEmpty NamedDict
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((NamedDict -> NamedDict)
 -> Maybe
      (Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict)))
 -> Maybe
      (Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict))))
-> (NamedDict -> NamedDict)
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
forall a b. (a -> b) -> a -> b
$ ([SourceType] -> [SourceType]) -> NamedDict -> NamedDict
forall v.
([SourceType] -> [SourceType])
-> TypeClassDictionaryInScope v -> TypeClassDictionaryInScope v
updateDict (([SourceType] -> [SourceType]) -> NamedDict -> NamedDict)
-> ([SourceType] -> [SourceType]) -> NamedDict -> NamedDict
forall a b. (a -> b) -> a -> b
$ (SourceType -> SourceType) -> [SourceType] -> [SourceType]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourceType -> SourceType
f
  updateCtx :: Map
  (Maybe ModuleName)
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Map
     (Maybe ModuleName)
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateCtx = (Maybe
   (Map
      (Qualified (ProperName 'ClassName))
      (Map (Qualified Ident) (NonEmpty NamedDict)))
 -> Maybe
      (Map
         (Qualified (ProperName 'ClassName))
         (Map (Qualified Ident) (NonEmpty NamedDict))))
-> Maybe ModuleName
-> Map
     (Maybe ModuleName)
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Map
     (Maybe ModuleName)
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
M.alter Maybe
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Maybe
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateScope Maybe ModuleName
forall a. Maybe a
Nothing