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

import Prelude
import Protolude (swap)

import Control.Monad
import Control.Monad.Trans.State

import Data.Foldable (fold)
import Data.Functor.Identity (runIdentity)
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 :: forall (m :: * -> *).
Applicative m =>
(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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Guard -> m Guard
f [Guard]
guards 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 (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 :: forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM a -> m a
go (ObjectLiteral [(PSString, a)]
as) = forall a. [(PSString, a)] -> Literal a
ObjectLiteral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (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) = forall a. [a] -> Literal a
ArrayLiteral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = 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 (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 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> Binder
h' [Binder]
bs) (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 (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 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> Declaration
f' [Declaration]
ds))
  f' (TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = Declaration -> Declaration
f (SourceAnn
-> SourceAnn
-> ChainId
-> Integer
-> Either Text Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args (([Declaration] -> [Declaration])
-> TypeInstanceBody -> TypeInstanceBody
mapTypeInstanceBody (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 (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' (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) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (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) (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 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> Expr
g' [Expr]
vs) (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 (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 (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 (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 (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 (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 :: forall a. (a -> a) -> Literal a -> Literal a
lit a -> a
go (ArrayLiteral [a]
as) = forall a. [a] -> Literal a
ArrayLiteral (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) = forall a. [(PSString, a)] -> Literal a
ObjectLiteral (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> Binder
h' (CaseAlternative -> [Binder]
caseAlternativeBinders CaseAlternative
ca)
       , caseAlternativeResult :: [GuardedExpr]
caseAlternativeResult = 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 (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 :: 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
f Expr -> m Expr
g Binder -> m Binder
h = (Declaration -> m Declaration
f' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f, Expr -> m Expr
g' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g, Binder -> m Binder
h' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) [Binder]
bs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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, ) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
val 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' 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 SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = SourceAnn
-> SourceAnn
-> ChainId
-> Integer
-> Either Text Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM (Expr -> m Expr
g 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
op forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v1 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Parens Expr
v) = Expr -> Expr
Parens forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
obj forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
obj forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
binder forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v1 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g')
  g' (Unused Expr
v) = Expr -> Expr
Unused forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v1 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v2 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v3 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Expr -> m Expr
g' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Expr -> m Expr
g) [Expr]
vs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Declaration -> m Declaration
f) [Declaration]
ds forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g Expr
v 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM (Binder -> m Binder
h 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b1 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Binder -> m Binder
h Binder
b2 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h') forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Binder -> m Binder
h Binder
b3 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h')
  h' (ParensInBinder Binder
b) = Binder -> Binder
ParensInBinder forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h Binder
b 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
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Binder -> m Binder
h' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) [Binder]
bs
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Declaration -> m Declaration
f' 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Binder -> m Binder
h' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Binder -> m Binder
h) Binder
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr -> m Expr
g' 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 :: 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
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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *).
Applicative m =>
(Guard -> m Guard)
-> (Expr -> m Expr) -> GuardedExpr -> m GuardedExpr
guardedExprM Guard -> m Guard
handleGuard Expr -> m Expr
g') [GuardedExpr]
val 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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, ) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
val) NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
expr) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' [Declaration]
ds) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Declaration -> m Declaration
f
  f' (TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = (SourceAnn
-> SourceAnn
-> ChainId
-> Integer
-> Either Text Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f') TypeInstanceBody
ds) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM Expr -> m Expr
g' Literal Expr
l) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
op forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Parens Expr
v) = (Expr -> Expr
Parens forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
obj forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (f :: * -> *) b c a.
Functor f =>
(b -> f c) -> (a, b) -> f (a, c)
sndM Expr -> m Expr
g') [(PSString, Expr)]
vs) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
obj forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
binder forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Expr -> m Expr
g
  g' (Unused Expr
v) = (Expr -> Expr
Unused forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v2 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v3) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr -> m Expr
g' [Expr]
vs forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CaseAlternative -> m CaseAlternative
handleCaseAlternative [CaseAlternative]
alts) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceType
ty) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Declaration -> m Declaration
f' [Declaration]
ds forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DoNotationElement -> m DoNotationElement
handleDoNotationElement [DoNotationElement]
es forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> m Expr
g' Expr
v) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Literal a -> m (Literal a)
litM Binder -> m Binder
h' Literal Binder
l) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Binder -> m Binder
h' Binder
b2 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Binder -> m Binder
h' Binder
b3) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Binder -> m Binder
h
  h' (ParensInBinder Binder
b) = (Binder -> Binder
ParensInBinder forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b) 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
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Binder -> m Binder
h' [Binder]
bs
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Binder -> m Binder
h' Binder
b 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 :: 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
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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> r
h' (forall a. ValueDeclarationData a -> [Binder]
valdeclBinders ValueDeclarationData [GuardedExpr]
vd) forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
v) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Guard -> r
k' [Guard]
grd forall a. [a] -> [a] -> [a]
++ [Expr -> r
g' Expr
v]) (forall a. ValueDeclarationData a -> a
valdeclExpression ValueDeclarationData [GuardedExpr]
vd))
  f' d :: Declaration
d@(BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Declaration -> r
f' [Declaration]
ds)
  f' d :: Declaration
d@(TypeInstanceDeclaration SourceAnn
_ SourceAnn
_ ChainId
_ Integer
_ Either Text Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Declaration -> r
f Declaration
d) (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) = 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@(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) = 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) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Expr -> r
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PSString, Expr)]
vs)
  g' v :: Expr
v@(ObjectUpdateNested Expr
obj PathTree Expr
vs) = 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) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl 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) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> r
g' [Expr]
vs)) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Expr -> r
g Expr
v) (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) = 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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (Binder -> r
h Binder
b) (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 :: forall a. r -> (a -> r) -> Literal a -> r
lit r
r a -> r
go (ArrayLiteral [a]
as) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> r
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) =
    forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (CaseAlternative -> r
i CaseAlternative
ca) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Binder -> r
h' [Binder]
bs forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
val) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Guard -> r
k' [Guard]
grd 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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (DoNotationElement -> r
j DoNotationElement
e) (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 :: 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
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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Binder -> r
h'' s
s) (forall a. ValueDeclarationData a -> [Binder]
valdeclBinders ValueDeclarationData [GuardedExpr]
vd) forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
v) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Guard -> r
k' s
s) [Guard]
grd forall a. [a] -> [a] -> [a]
++ [s -> Expr -> r
g'' s
s Expr
v]) (forall a. ValueDeclarationData a -> a
valdeclExpression ValueDeclarationData [GuardedExpr]
vd))
  f' s
s (BindingGroupDeclaration NonEmpty ((SourceAnn, Ident), NameKind, Expr)
ds) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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
_ SourceAnn
_ ChainId
_ Integer
_ Either Text Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = 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 (Accessor PSString
_ Expr
v1) = s -> Expr -> r
g'' s
s Expr
v1
  g' s
s (ObjectUpdate Expr
obj [(PSString, Expr)]
vs) = 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) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Expr -> r
g'' s
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PSString, Expr)]
vs)
  g' s
s (ObjectUpdateNested Expr
obj PathTree Expr
vs) = 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) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Expr -> r
g'' s
s) [Expr]
vs)) (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = 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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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 :: forall a. (s -> a -> r) -> s -> Literal a -> r
lit s -> a -> r
go s
s (ArrayLiteral [a]
as) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> a -> r
go s
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Binder -> r
h'' s
s) [Binder]
bs forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GuardedExpr [Guard]
grd Expr
val) -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (s -> Guard -> r
k' s
s) [Guard]
grd 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) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl r -> r -> r
(<>.) r
r0 (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

everywhereWithContextOnValues
  :: forall s
   . s
  -> (s -> Declaration       -> (s, Declaration))
  -> (s -> Expr              -> (s, Expr))
  -> (s -> Binder            -> (s, Binder))
  -> (s -> CaseAlternative   -> (s, CaseAlternative))
  -> (s -> DoNotationElement -> (s, DoNotationElement))
  -> (s -> Guard             -> (s, Guard))
  -> ( Declaration       -> Declaration
     , Expr              -> Expr
     , Binder            -> Binder
     , CaseAlternative   -> CaseAlternative
     , DoNotationElement -> DoNotationElement
     , Guard             -> Guard
     )
everywhereWithContextOnValues :: forall s.
s
-> (s -> Declaration -> (s, Declaration))
-> (s -> Expr -> (s, Expr))
-> (s -> Binder -> (s, Binder))
-> (s -> CaseAlternative -> (s, CaseAlternative))
-> (s -> DoNotationElement -> (s, DoNotationElement))
-> (s -> Guard -> (s, Guard))
-> (Declaration -> Declaration, Expr -> Expr, Binder -> Binder,
    CaseAlternative -> CaseAlternative,
    DoNotationElement -> DoNotationElement, Guard -> Guard)
everywhereWithContextOnValues s
s s -> Declaration -> (s, Declaration)
f s -> Expr -> (s, Expr)
g s -> Binder -> (s, Binder)
h s -> CaseAlternative -> (s, CaseAlternative)
i s -> DoNotationElement -> (s, DoNotationElement)
j s -> Guard -> (s, Guard)
k = (forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. Declaration -> Identity Declaration
f', forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Identity Expr
g', forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binder -> Identity Binder
h', forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. CaseAlternative -> Identity CaseAlternative
i', forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoNotationElement -> Identity DoNotationElement
j', forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. Guard -> Identity Guard
k')
  where
  (Declaration -> Identity Declaration
f', Expr -> Identity Expr
g', Binder -> Identity Binder
h', CaseAlternative -> Identity CaseAlternative
i', DoNotationElement -> Identity DoNotationElement
j', Guard -> Identity Guard
k') = 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))
-> (s -> Guard -> m (s, Guard))
-> (Declaration -> m Declaration, Expr -> m Expr,
    Binder -> m Binder, CaseAlternative -> m CaseAlternative,
    DoNotationElement -> m DoNotationElement, Guard -> m Guard)
everywhereWithContextOnValuesM s
s (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> Declaration -> (s, Declaration)
f) (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> Expr -> (s, Expr)
g) (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> Binder -> (s, Binder)
h) (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> CaseAlternative -> (s, CaseAlternative)
i) (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> DoNotationElement -> (s, DoNotationElement)
j) (forall {a} {a} {b}. (a -> a -> b) -> a -> a -> Identity b
wrap s -> Guard -> (s, Guard)
k)
  wrap :: (a -> a -> b) -> a -> a -> Identity b
wrap = ((forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall b c a. (b -> c) -> (a -> b) -> a -> c
.)

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))
  -> (s -> Guard             -> m (s, Guard))
  -> ( Declaration       -> m Declaration
     , Expr              -> m Expr
     , Binder            -> m Binder
     , CaseAlternative   -> m CaseAlternative
     , DoNotationElement -> m DoNotationElement
     , Guard             -> m Guard
     )
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))
-> (s -> Guard -> m (s, Guard))
-> (Declaration -> m Declaration, Expr -> m Expr,
    Binder -> m Binder, CaseAlternative -> m CaseAlternative,
    DoNotationElement -> m DoNotationElement, Guard -> m Guard)
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 -> Guard -> m (s, Guard)
k = (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, s -> Guard -> m Guard
k'' s
s0)
  where
  f'' :: s -> Declaration -> m Declaration
f'' s
s = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Declaration -> m Declaration
f' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args TypeInstanceBody
ds) = SourceAnn
-> SourceAnn
-> ChainId
-> Integer
-> Either Text Ident
-> [SourceConstraint]
-> Qualified (ProperName 'ClassName)
-> [SourceType]
-> TypeInstanceBody
-> Declaration
TypeInstanceDeclaration SourceAnn
sa SourceAnn
na ChainId
ch Integer
idx Either Text Ident
name [SourceConstraint]
cs Qualified (ProperName 'ClassName)
className [SourceType]
args forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *).
Applicative f =>
([Declaration] -> f [Declaration])
-> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody (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 = forall (m :: * -> *) a. Monad m => a -> m a
return Declaration
other

  g'' :: s -> Expr -> m Expr
g'' s
s = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Expr -> m Expr
g' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
op forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v1 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 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
obj forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
obj forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h' s
s Binder
binder 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v1 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Expr -> m Expr
g'' s
s Expr
v2 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s Expr
v forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 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 = forall (m :: * -> *) a. Monad m => a -> m a
return Expr
other

  h'' :: s -> Binder -> m Binder
h'' s
s = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Binder -> m Binder
h' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> s -> Binder -> m Binder
h'' s
s Binder
b2 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 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 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 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 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 = forall (m :: * -> *) a. Monad m => a -> m a
return Binder
other

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

  i'' :: s -> CaseAlternative -> m CaseAlternative
i'' s
s = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> CaseAlternative -> m CaseAlternative
i' 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (s -> GuardedExpr -> m GuardedExpr
guardedExprM' s
s) [GuardedExpr]
val

  -- A specialized `guardedExprM` that keeps track of the context `s`
  -- after traversing `guards`, such that it's also exposed to `expr`.
  guardedExprM' :: s -> GuardedExpr -> m GuardedExpr
  guardedExprM' :: s -> GuardedExpr -> m GuardedExpr
guardedExprM' s
s (GuardedExpr [Guard]
guards Expr
expr) = do
    ([Guard]
guards', s
s') <- forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. Guard -> s -> m (Guard, s)
goGuard) [Guard]
guards) s
s
    [Guard] -> Expr -> GuardedExpr
GuardedExpr [Guard]
guards' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Expr -> m Expr
g'' s
s' Expr
expr

  -- Like k'', but `s` is tracked.
  goGuard :: Guard -> s -> m (Guard, s)
  goGuard :: Guard -> s -> m (Guard, s)
goGuard Guard
x s
s  = s -> Guard -> m (s, Guard)
k s
s Guard
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> (b, a)
swap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b c.
Functor f =>
(a -> b -> f c) -> (a, b) -> f (a, c)
sndM' s -> Guard -> m Guard
k'

  j'' :: s -> DoNotationElement -> m DoNotationElement
j'' s
s = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> DoNotationElement -> m DoNotationElement
j' 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 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 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 = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry s -> Guard -> m Guard
k' forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< s -> Guard -> m (s, Guard)
k s
s

  k' :: s -> Guard -> m Guard
k' s
s (ConditionGuard Expr
e) = Expr -> Guard
ConditionGuard 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 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Binder -> m Binder
h'' s
s Binder
b 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
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
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
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
Ord)

inScope :: Ident -> S.Set ScopedIdent -> Bool
inScope :: Ident -> Set ScopedIdent -> Bool
inScope Ident
i Set ScopedIdent
s = (Ident -> ScopedIdent
LocalIdent Ident
i forall a. Ord a => a -> Set a -> Bool
`S.member` Set ScopedIdent
s) Bool -> Bool -> Bool
|| (Ident -> ScopedIdent
ToplevelIdent Ident
i 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 :: forall r.
Monoid r =>
(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 -> forall a b. (a, b) -> b
snd 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 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall a. Ord a => [a] -> Set a
S.fromList (forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
ToplevelIdent (forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent (forall a. NonEmpty a -> [a]
NEL.toList NonEmpty Declaration
ds))))
    in 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' = forall a. Ord a => a -> Set a -> Set a
S.insert (Ident -> ScopedIdent
ToplevelIdent Ident
name) Set ScopedIdent
s
        s'' :: Set ScopedIdent
s'' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s' (forall a. Ord a => [a] -> Set a
S.fromList (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Binder -> [ScopedIdent]
localBinderNames [Binder]
bs))
    in forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s') [Binder]
bs forall a. Semigroup a => a -> a -> a
<> 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall a. Ord a => [a] -> Set a
S.fromList (forall a. NonEmpty a -> [a]
NEL.toList (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 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) = 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
_ SourceAnn
_ ChainId
_ Integer
_ Either Text Ident
_ [SourceConstraint]
_ Qualified (ProperName 'ClassName)
_ [SourceType]
_ (ExplicitInstance [Declaration]
ds)) = 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
_ = 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 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) = 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 forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v1 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 (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 forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. Semigroup a => a -> a -> a
<> 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union (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 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 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 forall a. Semigroup a => a -> a -> a
<> Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s Expr
v2 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) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Expr -> r
g'' Set ScopedIdent
s) [Expr]
vs forall a. Semigroup a => a -> a -> a
<> 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall a. Ord a => [a] -> Set a
S.fromList (forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent (forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent [Declaration]
ds)))
    in forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Declaration -> r
f'' Set ScopedIdent
s') [Declaration]
ds 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) = forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL Set ScopedIdent -> DoNotationElement -> (Set ScopedIdent, r)
j'' Set ScopedIdent
s 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a b. (a, b) -> a
fst 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
_ = 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 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) = 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) = 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) = 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'' (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
_ = forall a. Monoid a => a
mempty

  lit :: (S.Set ScopedIdent -> a -> r) -> S.Set ScopedIdent -> Literal a -> r
  lit :: forall a.
(Set ScopedIdent -> a -> r) -> Set ScopedIdent -> Literal a -> r
lit Set ScopedIdent -> a -> r
go Set ScopedIdent
s (ArrayLiteral [a]
as) = 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) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> a -> r
go Set ScopedIdent
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PSString, a)]
as
  lit Set ScopedIdent -> a -> r
_ Set ScopedIdent
_ Literal a
_ = 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 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall a. Ord a => [a] -> Set a
S.fromList (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Binder -> [ScopedIdent]
localBinderNames [Binder]
bs))
    in forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set ScopedIdent -> Binder -> r
h'' Set ScopedIdent
s) [Binder]
bs forall a. Semigroup a => a -> a -> a
<> 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 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union (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 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union Set ScopedIdent
s (forall a. Ord a => [a] -> Set a
S.fromList (forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent (forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Declaration -> Maybe Ident
getDeclIdent [Declaration]
ds)))
    in (Set ScopedIdent
s', 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' = forall a. Ord a => Set a -> Set a -> Set a
S.union (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 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 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) = forall a. a -> Maybe a
Just (forall a. ValueDeclarationData a -> Ident
valdeclIdent ValueDeclarationData [GuardedExpr]
vd)
  getDeclIdent (TypeDeclaration TypeDeclarationData
td) = forall a. a -> Maybe a
Just (TypeDeclarationData -> Ident
tydeclIdent TypeDeclarationData
td)
  getDeclIdent Declaration
_ = forall a. Maybe a
Nothing

  localBinderNames :: Binder -> [ScopedIdent]
localBinderNames = forall a b. (a -> b) -> [a] -> [b]
map Ident -> ScopedIdent
LocalIdent 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 :: forall r.
Monoid r =>
(SourceType -> r)
-> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r,
    DoNotationElement -> r)
accumTypes SourceType -> r
f = 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 forall a. Monoid a => a -> a -> a
mappend Declaration -> r
forDecls Expr -> r
forValues Binder -> r
forBinders (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty)
  where
  forDecls :: Declaration -> r
forDecls (DataDeclaration SourceAnn
_ DataDeclType
_ ProperName 'TypeName
_ [(Text, Maybe SourceType)]
args [DataConstructorDeclaration]
dctors) =
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(Text, Maybe SourceType)]
args forall a. Semigroup a => a -> a -> a
<>
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (SourceType -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) 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]
_) =
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f)) [(Text, Maybe SourceType)]
args forall a. Semigroup a => a -> a -> a
<>
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Constraint a -> [Type a]
constraintArgs) [SourceConstraint]
implies
  forDecls (TypeInstanceDeclaration SourceAnn
_ SourceAnn
_ ChainId
_ Integer
_ Either Text Ident
_ [SourceConstraint]
cs Qualified (ProperName 'ClassName)
_ [SourceType]
tys TypeInstanceBody
_) =
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Constraint a -> [Type a]
constraintArgs) [SourceConstraint]
cs forall a. Semigroup a => a -> a -> a
<> 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) =
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(Text, Maybe SourceType)]
args 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
_ = forall a. Monoid a => a
mempty

  forValues :: Expr -> r
forValues (TypeClassDictionary SourceConstraint
c Map
  QualifiedBy
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
_ [ErrorMessageHint]
_) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SourceType -> r
f (forall a. Constraint a -> [Type a]
constraintArgs SourceConstraint
c)
  forValues (DeferredDictionary Qualified (ProperName 'ClassName)
_ [SourceType]
tys) = 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
_ = forall a. Monoid a => a
mempty

  forBinders :: Binder -> r
forBinders (TypedBinder SourceType
ty Binder
_) = SourceType -> r
f SourceType
ty
  forBinders Binder
_ = 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 forall a. a -> a
id Expr -> Expr
g 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
  QualifiedBy
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
sco [ErrorMessageHint]
hints) =
    SourceConstraint
-> Map
     QualifiedBy
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
-> [ErrorMessageHint]
-> Expr
TypeClassDictionary
      (forall a. ([Type a] -> [Type a]) -> Constraint a -> Constraint a
mapConstraintArgs (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourceType -> SourceType
f) SourceConstraint
c)
      (Map
  QualifiedBy
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Map
     QualifiedBy
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateCtx Map
  QualifiedBy
  (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 (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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ forall {v}.
([SourceType] -> [SourceType])
-> TypeClassDictionaryInScope v -> TypeClassDictionaryInScope v
updateDict forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SourceType -> SourceType
f
  updateCtx :: Map
  QualifiedBy
  (Map
     (Qualified (ProperName 'ClassName))
     (Map (Qualified Ident) (NonEmpty NamedDict)))
-> Map
     QualifiedBy
     (Map
        (Qualified (ProperName 'ClassName))
        (Map (Qualified Ident) (NonEmpty NamedDict)))
updateCtx = 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 QualifiedBy
ByNullSourcePos