{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
module GHC.Tc.Deriv.Functor
( FFoldType(..)
, functorLikeTraverse
, deepSubtypesContaining
, foldDataConArgs
, gen_Functor_binds
, gen_Foldable_binds
, gen_Traversable_binds
)
where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Data.Bag
import GHC.Core.DataCon
import GHC.Data.FastString
import GHC.Hs
import GHC.Utils.Outputable
import GHC.Builtin.Names
import GHC.Types.Name.Reader
import GHC.Types.SrcLoc
import GHC.Utils.Monad.State
import GHC.Tc.Deriv.Generate
import GHC.Tc.Utils.TcType
import GHC.Core.TyCon
import GHC.Core.TyCo.Rep
import GHC.Core.Type
import GHC.Utils.Misc
import GHC.Types.Var
import GHC.Types.Var.Set
import GHC.Types.Id.Make (coerceId)
import GHC.Builtin.Types (true_RDR, false_RDR)
import Data.Maybe (catMaybes, isJust)
gen_Functor_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Functor_binds :: SrcSpan -> TyCon -> (LHsBinds (GhcPass 'Parsed), BagDerivStuff)
gen_Functor_binds SrcSpan
loc TyCon
tycon
| Role
Phantom <- [Role] -> Role
forall a. [a] -> a
last (TyCon -> [Role]
tyConRoles TyCon
tycon)
= (LHsBind (GhcPass 'Parsed) -> LHsBinds (GhcPass 'Parsed)
forall a. a -> Bag a
unitBag LHsBind (GhcPass 'Parsed)
fmap_bind, BagDerivStuff
forall a. Bag a
emptyBag)
where
fmap_name :: GenLocated SrcSpan RdrName
fmap_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fmap_RDR
fmap_bind :: LHsBind (GhcPass 'Parsed)
fmap_bind = GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBind GenLocated SrcSpan RdrName
fmap_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
fmap_eqns
fmap_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
fmap_eqns = [HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
fmap_match_ctxt
[LPat (GhcPass 'Parsed)
nlWildPat]
LHsExpr (GhcPass 'Parsed)
coerce_Expr]
fmap_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
fmap_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
fmap_name
gen_Functor_binds SrcSpan
loc TyCon
tycon
= ([LHsBind (GhcPass 'Parsed)] -> LHsBinds (GhcPass 'Parsed)
forall a. [a] -> Bag a
listToBag [LHsBind (GhcPass 'Parsed)
fmap_bind, LHsBind (GhcPass 'Parsed)
replace_bind], BagDerivStuff
forall a. Bag a
emptyBag)
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
fmap_name :: GenLocated SrcSpan RdrName
fmap_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fmap_RDR
fmap_bind :: LHsBind (GhcPass 'Parsed)
fmap_bind = Int
-> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBindEC Int
2 LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall a. a -> a
id GenLocated SrcSpan RdrName
fmap_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
fmap_eqns
fmap_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
fmap_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
fmap_name
fmap_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
fmap_eqn DataCon
con = (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b c. (a -> b -> c) -> b -> a -> c
flip State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState [RdrName]
bs_RDRs (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con HsMatchContext (GhcPass 'Parsed)
fmap_match_ctxt [LPat (GhcPass 'Parsed)
f_Pat] DataCon
con [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
parts
where
parts :: [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
parts = FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
ft_fmap DataCon
con
fmap_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
fmap_eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
fmap_eqn [DataCon]
data_cons
ft_fmap :: FFoldType (LHsExpr GhcPs -> State [RdrName] (LHsExpr GhcPs))
ft_fmap :: FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
ft_fmap = FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_triv = \LHsExpr (GhcPass 'Parsed)
x -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure LHsExpr (GhcPass 'Parsed)
x
, ft_var :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_var = \LHsExpr (GhcPass 'Parsed)
x -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
f_Expr LHsExpr (GhcPass 'Parsed)
x
, ft_fun :: (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_fun = \LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
h LHsExpr (GhcPass 'Parsed)
x -> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
b -> do
LHsExpr (GhcPass 'Parsed)
gg <- LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
b
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
h (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
gg
, ft_tup :: TyCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_tup = ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase (HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
CaseAlt)
, ft_ty_app :: Type
-> Type
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_ty_app = \Type
_ Type
arg_ty LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x ->
if Type -> Bool
tcIsTyVarTy Type
arg_ty
then LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
fmap_RDR [LHsExpr (GhcPass 'Parsed)
f_Expr,LHsExpr (GhcPass 'Parsed)
x]
else do LHsExpr (GhcPass 'Parsed)
gg <- (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
fmap_RDR [LHsExpr (GhcPass 'Parsed)
gg,LHsExpr (GhcPass 'Parsed)
x]
, ft_forall :: Id
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_forall = \Id
_ LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x
, ft_bad_app :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_bad_app = String
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"in other argument in ft_fmap"
, ft_co_var :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_co_var = String
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"contravariant in ft_fmap" }
replace_name :: GenLocated SrcSpan RdrName
replace_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
replace_RDR
replace_bind :: LHsBind (GhcPass 'Parsed)
replace_bind = Int
-> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBindEC Int
2 LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall a. a -> a
id GenLocated SrcSpan RdrName
replace_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
replace_eqns
replace_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
replace_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
replace_name
replace_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
replace_eqn DataCon
con = (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b c. (a -> b -> c) -> b -> a -> c
flip State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState [RdrName]
bs_RDRs (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con HsMatchContext (GhcPass 'Parsed)
replace_match_ctxt [LPat (GhcPass 'Parsed)
z_Pat] DataCon
con [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
parts
where
parts :: [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
parts = FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
ft_replace DataCon
con
replace_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
replace_eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
replace_eqn [DataCon]
data_cons
ft_replace :: FFoldType (LHsExpr GhcPs -> State [RdrName] (LHsExpr GhcPs))
ft_replace :: FFoldType
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
ft_replace = FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_triv = \LHsExpr (GhcPass 'Parsed)
x -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure LHsExpr (GhcPass 'Parsed)
x
, ft_var :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_var = \LHsExpr (GhcPass 'Parsed)
_ -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure LHsExpr (GhcPass 'Parsed)
z_Expr
, ft_fun :: (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_fun = \LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
h LHsExpr (GhcPass 'Parsed)
x -> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
b -> do
LHsExpr (GhcPass 'Parsed)
gg <- LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
b
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
h (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
gg
, ft_tup :: TyCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_tup = ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase (HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
CaseAlt)
, ft_ty_app :: Type
-> Type
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_ty_app = \Type
_ Type
arg_ty LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x ->
if Type -> Bool
tcIsTyVarTy Type
arg_ty
then LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
replace_RDR [LHsExpr (GhcPass 'Parsed)
z_Expr,LHsExpr (GhcPass 'Parsed)
x]
else do LHsExpr (GhcPass 'Parsed)
gg <- (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
fmap_RDR [LHsExpr (GhcPass 'Parsed)
gg,LHsExpr (GhcPass 'Parsed)
x]
, ft_forall :: Id
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_forall = \Id
_ LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
g LHsExpr (GhcPass 'Parsed)
x
, ft_bad_app :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_bad_app = String
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"in other argument in ft_replace"
, ft_co_var :: LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
ft_co_var = String
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"contravariant in ft_replace" }
match_for_con :: Monad m
=> HsMatchContext GhcPs
-> [LPat GhcPs] -> DataCon
-> [LHsExpr GhcPs -> m (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
match_for_con :: forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con HsMatchContext (GhcPass 'Parsed)
ctxt = HsMatchContext (GhcPass 'Parsed)
-> (RdrName
-> [m (LHsExpr (GhcPass 'Parsed))]
-> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a.
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (RdrName -> [a] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch HsMatchContext (GhcPass 'Parsed)
ctxt ((RdrName
-> [m (LHsExpr (GhcPass 'Parsed))]
-> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> (RdrName
-> [m (LHsExpr (GhcPass 'Parsed))]
-> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$
\RdrName
con_name [m (LHsExpr (GhcPass 'Parsed))]
xsM -> do [LHsExpr (GhcPass 'Parsed)]
xs <- [m (LHsExpr (GhcPass 'Parsed))] -> m [LHsExpr (GhcPass 'Parsed)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [m (LHsExpr (GhcPass 'Parsed))]
xsM
LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
con_name [LHsExpr (GhcPass 'Parsed)]
xs
data FFoldType a
= FT { forall a. FFoldType a -> a
ft_triv :: a
, forall a. FFoldType a -> a
ft_var :: a
, forall a. FFoldType a -> a
ft_co_var :: a
, forall a. FFoldType a -> a -> a -> a
ft_fun :: a -> a -> a
, forall a. FFoldType a -> TyCon -> [a] -> a
ft_tup :: TyCon -> [a] -> a
, forall a. FFoldType a -> Type -> Type -> a -> a
ft_ty_app :: Type -> Type -> a -> a
, forall a. FFoldType a -> a
ft_bad_app :: a
, forall a. FFoldType a -> Id -> a -> a
ft_forall :: TcTyVar -> a -> a
}
functorLikeTraverse :: forall a.
TyVar
-> FFoldType a
-> Type
-> a
functorLikeTraverse :: forall a. Id -> FFoldType a -> Type -> a
functorLikeTraverse Id
var (FT { ft_triv :: forall a. FFoldType a -> a
ft_triv = a
caseTrivial, ft_var :: forall a. FFoldType a -> a
ft_var = a
caseVar
, ft_co_var :: forall a. FFoldType a -> a
ft_co_var = a
caseCoVar, ft_fun :: forall a. FFoldType a -> a -> a -> a
ft_fun = a -> a -> a
caseFun
, ft_tup :: forall a. FFoldType a -> TyCon -> [a] -> a
ft_tup = TyCon -> [a] -> a
caseTuple, ft_ty_app :: forall a. FFoldType a -> Type -> Type -> a -> a
ft_ty_app = Type -> Type -> a -> a
caseTyApp
, ft_bad_app :: forall a. FFoldType a -> a
ft_bad_app = a
caseWrongArg, ft_forall :: forall a. FFoldType a -> Id -> a -> a
ft_forall = Id -> a -> a
caseForAll })
Type
ty
= (a, Bool) -> a
forall a b. (a, b) -> a
fst (Bool -> Type -> (a, Bool)
go Bool
False Type
ty)
where
go :: Bool
-> Type
-> (a, Bool)
go :: Bool -> Type -> (a, Bool)
go Bool
co Type
ty | Just Type
ty' <- Type -> Maybe Type
tcView Type
ty = Bool -> Type -> (a, Bool)
go Bool
co Type
ty'
go Bool
co (TyVarTy Id
v) | Id
v Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
== Id
var = (if Bool
co then a
caseCoVar else a
caseVar,Bool
True)
go Bool
co (FunTy { ft_arg :: Type -> Type
ft_arg = Type
x, ft_res :: Type -> Type
ft_res = Type
y, ft_af :: Type -> AnonArgFlag
ft_af = AnonArgFlag
af })
| AnonArgFlag
InvisArg <- AnonArgFlag
af = Bool -> Type -> (a, Bool)
go Bool
co Type
y
| Bool
xc Bool -> Bool -> Bool
|| Bool
yc = (a -> a -> a
caseFun a
xr a
yr,Bool
True)
where (a
xr,Bool
xc) = Bool -> Type -> (a, Bool)
go (Bool -> Bool
not Bool
co) Type
x
(a
yr,Bool
yc) = Bool -> Type -> (a, Bool)
go Bool
co Type
y
go Bool
co (AppTy Type
x Type
y) | Bool
xc = (a
caseWrongArg, Bool
True)
| Bool
yc = (Type -> Type -> a -> a
caseTyApp Type
x Type
y a
yr, Bool
True)
where (a
_, Bool
xc) = Bool -> Type -> (a, Bool)
go Bool
co Type
x
(a
yr,Bool
yc) = Bool -> Type -> (a, Bool)
go Bool
co Type
y
go Bool
co ty :: Type
ty@(TyConApp TyCon
con [Type]
args)
| Bool -> Bool
not ([Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
xcs) = (a
caseTrivial, Bool
False)
| TyCon -> Bool
isTupleTyCon TyCon
con = (TyCon -> [a] -> a
caseTuple TyCon
con [a]
xrs, Bool
True)
| [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> [Bool]
forall a. [a] -> [a]
init [Bool]
xcs) = (a
caseWrongArg, Bool
True)
| Just (Type
fun_ty, Type
arg_ty) <- Type -> Maybe (Type, Type)
splitAppTy_maybe Type
ty
= (Type -> Type -> a -> a
caseTyApp Type
fun_ty Type
arg_ty ([a] -> a
forall a. [a] -> a
last [a]
xrs), Bool
True)
| Bool
otherwise = (a
caseWrongArg, Bool
True)
where
([a]
xrs,[Bool]
xcs) = [(a, Bool)] -> ([a], [Bool])
forall a b. [(a, b)] -> ([a], [b])
unzip ((Type -> (a, Bool)) -> [Type] -> [(a, Bool)]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> Type -> (a, Bool)
go Bool
co) ([Type] -> [Type]
dropRuntimeRepArgs [Type]
args))
go Bool
co (ForAllTy (Bndr Id
v ArgFlag
vis) Type
x)
| ArgFlag -> Bool
isVisibleArgFlag ArgFlag
vis = String -> (a, Bool)
forall a. String -> a
panic String
"unexpected visible binder"
| Id
v Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
/= Id
var Bool -> Bool -> Bool
&& Bool
xc = (Id -> a -> a
caseForAll Id
v a
xr,Bool
True)
where (a
xr,Bool
xc) = Bool -> Type -> (a, Bool)
go Bool
co Type
x
go Bool
_ Type
_ = (a
caseTrivial,Bool
False)
deepSubtypesContaining :: TyVar -> Type -> [TcType]
deepSubtypesContaining :: Id -> Type -> [Type]
deepSubtypesContaining Id
tv
= Id -> FFoldType [Type] -> Type -> [Type]
forall a. Id -> FFoldType a -> Type -> a
functorLikeTraverse Id
tv
(FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: [Type]
ft_triv = []
, ft_var :: [Type]
ft_var = []
, ft_fun :: [Type] -> [Type] -> [Type]
ft_fun = [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
(++)
, ft_tup :: TyCon -> [[Type]] -> [Type]
ft_tup = \TyCon
_ [[Type]]
xs -> [[Type]] -> [Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Type]]
xs
, ft_ty_app :: Type -> Type -> [Type] -> [Type]
ft_ty_app = \Type
t Type
_ [Type]
ts -> Type
tType -> [Type] -> [Type]
forall a. a -> [a] -> [a]
:[Type]
ts
, ft_bad_app :: [Type]
ft_bad_app = String -> [Type]
forall a. String -> a
panic String
"in other argument in deepSubtypesContaining"
, ft_co_var :: [Type]
ft_co_var = String -> [Type]
forall a. String -> a
panic String
"contravariant in deepSubtypesContaining"
, ft_forall :: Id -> [Type] -> [Type]
ft_forall = \Id
v [Type]
xs -> (Type -> Bool) -> [Type] -> [Type]
forall a. (a -> Bool) -> [a] -> [a]
filterOut ((Id
v Id -> VarSet -> Bool
`elemVarSet`) (VarSet -> Bool) -> (Type -> VarSet) -> Type -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> VarSet
tyCoVarsOfType) [Type]
xs })
foldDataConArgs :: FFoldType a -> DataCon -> [a]
foldDataConArgs :: forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType a
ft DataCon
con
= (Type -> a) -> [Type] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Type -> a
foldArg ((Scaled Type -> Type) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Scaled Type -> Type
forall a. Scaled a -> a
scaledThing ([Scaled Type] -> [Type]) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> a -> b
$ DataCon -> [Scaled Type]
dataConOrigArgTys DataCon
con)
where
foldArg :: Type -> a
foldArg
= case Type -> Maybe Id
getTyVar_maybe ([Type] -> Type
forall a. [a] -> a
last (Type -> [Type]
tyConAppArgs (DataCon -> Type
dataConOrigResTy DataCon
con))) of
Just Id
tv -> Id -> FFoldType a -> Type -> a
forall a. Id -> FFoldType a -> Type -> a
functorLikeTraverse Id
tv FFoldType a
ft
Maybe Id
Nothing -> a -> Type -> a
forall a b. a -> b -> a
const (FFoldType a -> a
forall a. FFoldType a -> a
ft_triv FFoldType a
ft)
mkSimpleLam :: (LHsExpr GhcPs -> State [RdrName] (LHsExpr GhcPs))
-> State [RdrName] (LHsExpr GhcPs)
mkSimpleLam :: (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
lam =
State [RdrName] [RdrName]
forall s. State s s
get State [RdrName] [RdrName]
-> ([RdrName] -> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
RdrName
n:[RdrName]
names -> do
[RdrName] -> State [RdrName] ()
forall s. s -> State s ()
put [RdrName]
names
LHsExpr (GhcPass 'Parsed)
body <- LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
lam (IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
n)
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return ([LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (p :: Pass).
(IsPass p, XMG (GhcPass p) (LHsExpr (GhcPass p)) ~ NoExtField) =>
[LPat (GhcPass p)] -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
mkHsLam [IdP (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat RdrName
IdP (GhcPass 'Parsed)
n] LHsExpr (GhcPass 'Parsed)
body)
[RdrName]
_ -> String -> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"mkSimpleLam"
mkSimpleLam2 :: (LHsExpr GhcPs -> LHsExpr GhcPs
-> State [RdrName] (LHsExpr GhcPs))
-> State [RdrName] (LHsExpr GhcPs)
mkSimpleLam2 :: (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam2 LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
lam =
State [RdrName] [RdrName]
forall s. State s s
get State [RdrName] [RdrName]
-> ([RdrName] -> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
RdrName
n1:RdrName
n2:[RdrName]
names -> do
[RdrName] -> State [RdrName] ()
forall s. s -> State s ()
put [RdrName]
names
LHsExpr (GhcPass 'Parsed)
body <- LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
lam (IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
n1) (IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
n2)
LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return ([LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (p :: Pass).
(IsPass p, XMG (GhcPass p) (LHsExpr (GhcPass p)) ~ NoExtField) =>
[LPat (GhcPass p)] -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
mkHsLam [IdP (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat RdrName
IdP (GhcPass 'Parsed)
n1,IdP (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat RdrName
IdP (GhcPass 'Parsed)
n2] LHsExpr (GhcPass 'Parsed)
body)
[RdrName]
_ -> String -> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a. String -> a
panic String
"mkSimpleLam2"
mkSimpleConMatch :: Monad m => HsMatchContext GhcPs
-> (RdrName -> [a] -> m (LHsExpr GhcPs))
-> [LPat GhcPs]
-> DataCon
-> [LHsExpr GhcPs -> a]
-> m (LMatch GhcPs (LHsExpr GhcPs))
mkSimpleConMatch :: forall (m :: * -> *) a.
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (RdrName -> [a] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [LHsExpr (GhcPass 'Parsed) -> a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch HsMatchContext (GhcPass 'Parsed)
ctxt RdrName -> [a] -> m (LHsExpr (GhcPass 'Parsed))
fold [LPat (GhcPass 'Parsed)]
extra_pats DataCon
con [LHsExpr (GhcPass 'Parsed) -> a]
insides = do
let con_name :: RdrName
con_name = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
con
let vars_needed :: [RdrName]
vars_needed = [LHsExpr (GhcPass 'Parsed) -> a] -> [RdrName] -> [RdrName]
forall b a. [b] -> [a] -> [a]
takeList [LHsExpr (GhcPass 'Parsed) -> a]
insides [RdrName]
as_RDRs
let bare_pat :: LPat (GhcPass 'Parsed)
bare_pat = RdrName -> [RdrName] -> LPat (GhcPass 'Parsed)
nlConVarPat RdrName
con_name [RdrName]
vars_needed
let pat :: LPat (GhcPass 'Parsed)
pat = if [RdrName] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [RdrName]
vars_needed
then LPat (GhcPass 'Parsed)
bare_pat
else LPat (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (name :: Pass). LPat (GhcPass name) -> LPat (GhcPass name)
nlParPat LPat (GhcPass 'Parsed)
bare_pat
LHsExpr (GhcPass 'Parsed)
rhs <- RdrName -> [a] -> m (LHsExpr (GhcPass 'Parsed))
fold RdrName
con_name
(((LHsExpr (GhcPass 'Parsed) -> a) -> RdrName -> a)
-> [LHsExpr (GhcPass 'Parsed) -> a] -> [RdrName] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\LHsExpr (GhcPass 'Parsed) -> a
i RdrName
v -> LHsExpr (GhcPass 'Parsed) -> a
i (LHsExpr (GhcPass 'Parsed) -> a) -> LHsExpr (GhcPass 'Parsed) -> a
forall a b. (a -> b) -> a -> b
$ IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
v) [LHsExpr (GhcPass 'Parsed) -> a]
insides [RdrName]
vars_needed)
LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass).
IsPass p =>
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
ctxt ([Located (Pat (GhcPass 'Parsed))]
[LPat (GhcPass 'Parsed)]
extra_pats [Located (Pat (GhcPass 'Parsed))]
-> [Located (Pat (GhcPass 'Parsed))]
-> [Located (Pat (GhcPass 'Parsed))]
forall a. [a] -> [a] -> [a]
++ [Located (Pat (GhcPass 'Parsed))
LPat (GhcPass 'Parsed)
pat]) LHsExpr (GhcPass 'Parsed)
rhs
(HsLocalBinds (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
forall e. e -> Located e
noLoc HsLocalBinds (GhcPass 'Parsed)
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)
mkSimpleConMatch2 :: Monad m
=> HsMatchContext GhcPs
-> (LHsExpr GhcPs -> [LHsExpr GhcPs]
-> m (LHsExpr GhcPs))
-> [LPat GhcPs]
-> DataCon
-> [Maybe (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
mkSimpleConMatch2 :: forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch2 HsMatchContext (GhcPass 'Parsed)
ctxt LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed))
fold [LPat (GhcPass 'Parsed)]
extra_pats DataCon
con [Maybe (LHsExpr (GhcPass 'Parsed))]
insides = do
let con_name :: RdrName
con_name = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
con
vars_needed :: [RdrName]
vars_needed = [Maybe (LHsExpr (GhcPass 'Parsed))] -> [RdrName] -> [RdrName]
forall b a. [b] -> [a] -> [a]
takeList [Maybe (LHsExpr (GhcPass 'Parsed))]
insides [RdrName]
as_RDRs
pat :: LPat (GhcPass 'Parsed)
pat = RdrName -> [RdrName] -> LPat (GhcPass 'Parsed)
nlConVarPat RdrName
con_name [RdrName]
vars_needed
exps :: [LHsExpr (GhcPass 'Parsed)]
exps = [Maybe (LHsExpr (GhcPass 'Parsed))] -> [LHsExpr (GhcPass 'Parsed)]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe (LHsExpr (GhcPass 'Parsed))]
-> [LHsExpr (GhcPass 'Parsed)])
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> [LHsExpr (GhcPass 'Parsed)]
forall a b. (a -> b) -> a -> b
$ (Maybe (LHsExpr (GhcPass 'Parsed))
-> RdrName -> Maybe (LHsExpr (GhcPass 'Parsed)))
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> [RdrName]
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Maybe (LHsExpr (GhcPass 'Parsed))
i RdrName
v -> (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
v) (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LHsExpr (GhcPass 'Parsed))
i)
[Maybe (LHsExpr (GhcPass 'Parsed))]
insides [RdrName]
vars_needed
argTysTyVarInfo :: [Bool]
argTysTyVarInfo = (Maybe (LHsExpr (GhcPass 'Parsed)) -> Bool)
-> [Maybe (LHsExpr (GhcPass 'Parsed))] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map Maybe (LHsExpr (GhcPass 'Parsed)) -> Bool
forall a. Maybe a -> Bool
isJust [Maybe (LHsExpr (GhcPass 'Parsed))]
insides
([LHsExpr (GhcPass 'Parsed)]
asWithTyVar, [LHsExpr (GhcPass 'Parsed)]
asWithoutTyVar) = [Bool]
-> [LHsExpr (GhcPass 'Parsed)]
-> ([LHsExpr (GhcPass 'Parsed)], [LHsExpr (GhcPass 'Parsed)])
forall a. [Bool] -> [a] -> ([a], [a])
partitionByList [Bool]
argTysTyVarInfo [LHsExpr (GhcPass 'Parsed)]
as_Vars
con_expr :: LHsExpr (GhcPass 'Parsed)
con_expr
| [LHsExpr (GhcPass 'Parsed)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsExpr (GhcPass 'Parsed)]
asWithTyVar = IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
con_name [LHsExpr (GhcPass 'Parsed)]
asWithoutTyVar
| Bool
otherwise =
let bs :: [RdrName]
bs = [Bool] -> [RdrName] -> [RdrName]
forall a. [Bool] -> [a] -> [a]
filterByList [Bool]
argTysTyVarInfo [RdrName]
bs_RDRs
vars :: [LHsExpr (GhcPass 'Parsed)]
vars = [Bool]
-> [LHsExpr (GhcPass 'Parsed)]
-> [LHsExpr (GhcPass 'Parsed)]
-> [LHsExpr (GhcPass 'Parsed)]
forall a. [Bool] -> [a] -> [a] -> [a]
filterByLists [Bool]
argTysTyVarInfo [LHsExpr (GhcPass 'Parsed)]
bs_Vars [LHsExpr (GhcPass 'Parsed)]
as_Vars
in [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (p :: Pass).
(IsPass p, XMG (GhcPass p) (LHsExpr (GhcPass p)) ~ NoExtField) =>
[LPat (GhcPass p)] -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
mkHsLam ((RdrName -> Located (Pat (GhcPass 'Parsed)))
-> [RdrName] -> [Located (Pat (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> Located (Pat (GhcPass 'Parsed))
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat [RdrName]
bs) (IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
con_name [LHsExpr (GhcPass 'Parsed)]
vars)
LHsExpr (GhcPass 'Parsed)
rhs <- LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed))
fold LHsExpr (GhcPass 'Parsed)
con_expr [LHsExpr (GhcPass 'Parsed)]
exps
LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass).
IsPass p =>
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
ctxt ([Located (Pat (GhcPass 'Parsed))]
[LPat (GhcPass 'Parsed)]
extra_pats [Located (Pat (GhcPass 'Parsed))]
-> [Located (Pat (GhcPass 'Parsed))]
-> [Located (Pat (GhcPass 'Parsed))]
forall a. [a] -> [a] -> [a]
++ [Located (Pat (GhcPass 'Parsed))
LPat (GhcPass 'Parsed)
pat]) LHsExpr (GhcPass 'Parsed)
rhs
(HsLocalBinds (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
forall e. e -> Located e
noLoc HsLocalBinds (GhcPass 'Parsed)
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)
mkSimpleTupleCase :: Monad m => ([LPat GhcPs] -> DataCon -> [a]
-> m (LMatch GhcPs (LHsExpr GhcPs)))
-> TyCon -> [a] -> LHsExpr GhcPs -> m (LHsExpr GhcPs)
mkSimpleTupleCase :: forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase [LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con TyCon
tc [a]
insides LHsExpr (GhcPass 'Parsed)
x
= do { let data_con :: DataCon
data_con = TyCon -> DataCon
tyConSingleDataCon TyCon
tc
; LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
match <- [LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con [] DataCon
data_con [a]
insides
; LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Parsed)
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
nlHsCase LHsExpr (GhcPass 'Parsed)
x [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
match] }
gen_Foldable_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Foldable_binds :: SrcSpan -> TyCon -> (LHsBinds (GhcPass 'Parsed), BagDerivStuff)
gen_Foldable_binds SrcSpan
loc TyCon
tycon
| Role
Phantom <- [Role] -> Role
forall a. [a] -> a
last (TyCon -> [Role]
tyConRoles TyCon
tycon)
= (LHsBind (GhcPass 'Parsed) -> LHsBinds (GhcPass 'Parsed)
forall a. a -> Bag a
unitBag LHsBind (GhcPass 'Parsed)
foldMap_bind, BagDerivStuff
forall a. Bag a
emptyBag)
where
foldMap_name :: GenLocated SrcSpan RdrName
foldMap_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
foldMap_RDR
foldMap_bind :: LHsBind (GhcPass 'Parsed)
foldMap_bind = GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBind GenLocated SrcSpan RdrName
foldMap_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
foldMap_eqns
foldMap_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
foldMap_eqns = [HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
foldMap_match_ctxt
[LPat (GhcPass 'Parsed)
nlWildPat, LPat (GhcPass 'Parsed)
nlWildPat]
LHsExpr (GhcPass 'Parsed)
mempty_Expr]
foldMap_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
foldMap_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
foldMap_name
gen_Foldable_binds SrcSpan
loc TyCon
tycon
| [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
data_cons
= (LHsBind (GhcPass 'Parsed) -> LHsBinds (GhcPass 'Parsed)
forall a. a -> Bag a
unitBag LHsBind (GhcPass 'Parsed)
foldMap_bind, BagDerivStuff
forall a. Bag a
emptyBag)
| Bool
otherwise
= ([LHsBind (GhcPass 'Parsed)] -> LHsBinds (GhcPass 'Parsed)
forall a. [a] -> Bag a
listToBag [LHsBind (GhcPass 'Parsed)
foldr_bind, LHsBind (GhcPass 'Parsed)
foldMap_bind, LHsBind (GhcPass 'Parsed)
null_bind], BagDerivStuff
forall a. Bag a
emptyBag)
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
foldr_bind :: LHsBind (GhcPass 'Parsed)
foldr_bind = GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBind (SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
foldable_foldr_RDR) [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
eqns
eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
foldr_eqn [DataCon]
data_cons
foldr_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
foldr_eqn DataCon
con
= State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState (LHsExpr (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
LHsExpr (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldr LHsExpr (GhcPass 'Parsed)
z_Expr [LPat (GhcPass 'Parsed)
f_Pat,LPat (GhcPass 'Parsed)
z_Pat] DataCon
con ([Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts) [RdrName]
bs_RDRs
where
parts :: State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts = [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))])
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> a -> b
$ FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
-> DataCon -> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_foldr DataCon
con
foldMap_name :: GenLocated SrcSpan RdrName
foldMap_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
foldMap_RDR
foldMap_bind :: LHsBind (GhcPass 'Parsed)
foldMap_bind = Int
-> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBindEC Int
2 (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall a b. a -> b -> a
const LHsExpr (GhcPass 'Parsed)
mempty_Expr)
GenLocated SrcSpan RdrName
foldMap_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
foldMap_eqns
foldMap_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
foldMap_eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
foldMap_eqn [DataCon]
data_cons
foldMap_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
foldMap_eqn DataCon
con
= State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldMap [LPat (GhcPass 'Parsed)
f_Pat] DataCon
con ([Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts) [RdrName]
bs_RDRs
where
parts :: State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts = [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))])
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> a -> b
$ FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
-> DataCon -> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_foldMap DataCon
con
convert :: [NullM a] -> Maybe [Maybe a]
convert :: forall a. [NullM a] -> Maybe [Maybe a]
convert = (NullM a -> Maybe (Maybe a)) -> [NullM a] -> Maybe [Maybe a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NullM a -> Maybe (Maybe a)
forall {a}. NullM a -> Maybe (Maybe a)
go where
go :: NullM a -> Maybe (Maybe a)
go NullM a
IsNull = Maybe a -> Maybe (Maybe a)
forall a. a -> Maybe a
Just Maybe a
forall a. Maybe a
Nothing
go NullM a
NotNull = Maybe (Maybe a)
forall a. Maybe a
Nothing
go (NullM a
a) = Maybe a -> Maybe (Maybe a)
forall a. a -> Maybe a
Just (a -> Maybe a
forall a. a -> Maybe a
Just a
a)
null_name :: GenLocated SrcSpan RdrName
null_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
null_RDR
null_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
null_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
null_name
null_bind :: LHsBind (GhcPass 'Parsed)
null_bind = GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBind GenLocated SrcSpan RdrName
null_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
null_eqns
null_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
null_eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
null_eqn [DataCon]
data_cons
null_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
null_eqn DataCon
con
= (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b c. (a -> b -> c) -> b -> a -> c
flip State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState [RdrName]
bs_RDRs (State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ do
[NullM (LHsExpr (GhcPass 'Parsed))]
parts <- [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [NullM (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [NullM (LHsExpr (GhcPass 'Parsed))])
-> [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [NullM (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> a -> b
$ FFoldType (State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed))))
-> DataCon -> [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType (State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed))))
ft_null DataCon
con
case [NullM (LHsExpr (GhcPass 'Parsed))]
-> Maybe [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a. [NullM a] -> Maybe [Maybe a]
convert [NullM (LHsExpr (GhcPass 'Parsed))]
parts of
Maybe [Maybe (LHsExpr (GhcPass 'Parsed))]
Nothing -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass).
IsPass p =>
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
null_match_ctxt [LPat (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (name :: Pass). LPat (GhcPass name) -> LPat (GhcPass name)
nlParPat (DataCon -> LPat (GhcPass 'Parsed)
nlWildConPat DataCon
con)]
LHsExpr (GhcPass 'Parsed)
false_Expr (HsLocalBinds (GhcPass 'Parsed)
-> Located (HsLocalBinds (GhcPass 'Parsed))
forall e. e -> Located e
noLoc HsLocalBinds (GhcPass 'Parsed)
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)
Just [Maybe (LHsExpr (GhcPass 'Parsed))]
cp -> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_null [] DataCon
con [Maybe (LHsExpr (GhcPass 'Parsed))]
cp
ft_foldr :: FFoldType (State [RdrName] (Maybe (LHsExpr GhcPs)))
ft_foldr :: FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_foldr
= FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_triv = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (LHsExpr (GhcPass 'Parsed))
forall a. Maybe a
Nothing
, ft_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_var = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
-> Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
f_Expr
, ft_tup :: TyCon
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_tup = \TyCon
t [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
g -> do
[Maybe (LHsExpr (GhcPass 'Parsed))]
gg <- [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
g
LHsExpr (GhcPass 'Parsed)
lam <- (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam2 ((LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
z ->
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase (LHsExpr (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
LHsExpr (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldr LHsExpr (GhcPass 'Parsed)
z) TyCon
t [Maybe (LHsExpr (GhcPass 'Parsed))]
gg LHsExpr (GhcPass 'Parsed)
x
Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
lam)
, ft_ty_app :: Type
-> Type
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_ty_app = \Type
_ Type
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> do
Maybe (LHsExpr (GhcPass 'Parsed))
gg <- State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
(LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\LHsExpr (GhcPass 'Parsed)
gg' -> (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam2 ((LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
z -> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$
IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
foldable_foldr_RDR [LHsExpr (GhcPass 'Parsed)
gg',LHsExpr (GhcPass 'Parsed)
z,LHsExpr (GhcPass 'Parsed)
x]) Maybe (LHsExpr (GhcPass 'Parsed))
gg
, ft_forall :: Id
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_forall = \Id
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
, ft_co_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_co_var = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"contravariant in ft_foldr"
, ft_fun :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_fun = String
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"function in ft_foldr"
, ft_bad_app :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_bad_app = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"in other argument in ft_foldr" }
match_foldr :: Monad m
=> LHsExpr GhcPs
-> [LPat GhcPs]
-> DataCon
-> [Maybe (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
match_foldr :: forall (m :: * -> *).
Monad m =>
LHsExpr (GhcPass 'Parsed)
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldr LHsExpr (GhcPass 'Parsed)
z = HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch2 HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
LambdaExpr ((LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
_ [LHsExpr (GhcPass 'Parsed)]
xs -> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkFoldr [LHsExpr (GhcPass 'Parsed)]
xs)
where
mkFoldr :: [LHsExpr GhcPs] -> LHsExpr GhcPs
mkFoldr :: [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkFoldr = (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
z
ft_foldMap :: FFoldType (State [RdrName] (Maybe (LHsExpr GhcPs)))
ft_foldMap :: FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_foldMap
= FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_triv = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (LHsExpr (GhcPass 'Parsed))
forall a. Maybe a
Nothing
, ft_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_var = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
f_Expr)
, ft_tup :: TyCon
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_tup = \TyCon
t [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
g -> do
[Maybe (LHsExpr (GhcPass 'Parsed))]
gg <- [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
g
LHsExpr (GhcPass 'Parsed)
lam <- (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldMap TyCon
t [Maybe (LHsExpr (GhcPass 'Parsed))]
gg
Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
lam)
, ft_ty_app :: Type
-> Type
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_ty_app = \Type
_ Type
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
foldMap_Expr) (Maybe (LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
, ft_forall :: Id
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_forall = \Id
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
, ft_co_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_co_var = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"contravariant in ft_foldMap"
, ft_fun :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_fun = String
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"function in ft_foldMap"
, ft_bad_app :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_bad_app = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"in other argument in ft_foldMap" }
match_foldMap :: Monad m
=> [LPat GhcPs]
-> DataCon
-> [Maybe (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
match_foldMap :: forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_foldMap = HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch2 HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
CaseAlt ((LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
_ [LHsExpr (GhcPass 'Parsed)]
xs -> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkFoldMap [LHsExpr (GhcPass 'Parsed)]
xs)
where
mkFoldMap :: [LHsExpr GhcPs] -> LHsExpr GhcPs
mkFoldMap :: [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkFoldMap [] = LHsExpr (GhcPass 'Parsed)
mempty_Expr
mkFoldMap [LHsExpr (GhcPass 'Parsed)]
xs = (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (\LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
y -> IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
mappend_RDR [LHsExpr (GhcPass 'Parsed)
x,LHsExpr (GhcPass 'Parsed)
y]) [LHsExpr (GhcPass 'Parsed)]
xs
ft_null :: FFoldType (State [RdrName] (NullM (LHsExpr GhcPs)))
ft_null :: FFoldType (State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed))))
ft_null
= FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_triv = NullM (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return NullM (LHsExpr (GhcPass 'Parsed))
forall a. NullM a
IsNull
, ft_var :: State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_var = NullM (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return NullM (LHsExpr (GhcPass 'Parsed))
forall a. NullM a
NotNull
, ft_tup :: TyCon
-> [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_tup = \TyCon
t [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
g -> do
[NullM (LHsExpr (GhcPass 'Parsed))]
gg <- [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [NullM (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))]
g
case [NullM (LHsExpr (GhcPass 'Parsed))]
-> Maybe [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a. [NullM a] -> Maybe [Maybe a]
convert [NullM (LHsExpr (GhcPass 'Parsed))]
gg of
Maybe [Maybe (LHsExpr (GhcPass 'Parsed))]
Nothing -> NullM (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall (f :: * -> *) a. Applicative f => a -> f a
pure NullM (LHsExpr (GhcPass 'Parsed))
forall a. NullM a
NotNull
Just [Maybe (LHsExpr (GhcPass 'Parsed))]
ggg ->
LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed))
forall a. a -> NullM a
NullM (LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_null TyCon
t [Maybe (LHsExpr (GhcPass 'Parsed))]
ggg)
, ft_ty_app :: Type
-> Type
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_ty_app = \Type
_ Type
_ State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
g -> ((NullM (LHsExpr (GhcPass 'Parsed))
-> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed))))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> (NullM (LHsExpr (GhcPass 'Parsed))
-> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall a b c. (a -> b -> c) -> b -> a -> c
flip (NullM (LHsExpr (GhcPass 'Parsed))
-> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
g ((NullM (LHsExpr (GhcPass 'Parsed))
-> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed))))
-> (NullM (LHsExpr (GhcPass 'Parsed))
-> NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ \NullM (LHsExpr (GhcPass 'Parsed))
nestedResult ->
case NullM (LHsExpr (GhcPass 'Parsed))
nestedResult of
NullM (LHsExpr (GhcPass 'Parsed))
NotNull -> LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed))
forall a. a -> NullM a
NullM LHsExpr (GhcPass 'Parsed)
null_Expr
NullM (LHsExpr (GhcPass 'Parsed))
IsNull -> NullM (LHsExpr (GhcPass 'Parsed))
forall a. NullM a
IsNull
NullM LHsExpr (GhcPass 'Parsed)
nestedTest -> LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed))
forall a. a -> NullM a
NullM (LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed)))
-> LHsExpr (GhcPass 'Parsed) -> NullM (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$
LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
all_Expr LHsExpr (GhcPass 'Parsed)
nestedTest
, ft_forall :: Id
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_forall = \Id
_ State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
g -> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
g
, ft_co_var :: State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_co_var = String -> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"contravariant in ft_null"
, ft_fun :: State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_fun = String
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"function in ft_null"
, ft_bad_app :: State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
ft_bad_app = String -> State [RdrName] (NullM (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"in other argument in ft_null" }
match_null :: Monad m
=> [LPat GhcPs]
-> DataCon
-> [Maybe (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
match_null :: forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_null = HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch2 HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
CaseAlt ((LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$ \LHsExpr (GhcPass 'Parsed)
_ [LHsExpr (GhcPass 'Parsed)]
xs -> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkNull [LHsExpr (GhcPass 'Parsed)]
xs)
where
mkNull :: [LHsExpr GhcPs] -> LHsExpr GhcPs
mkNull :: [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkNull [] = LHsExpr (GhcPass 'Parsed)
true_Expr
mkNull [LHsExpr (GhcPass 'Parsed)]
xs = (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (\LHsExpr (GhcPass 'Parsed)
x LHsExpr (GhcPass 'Parsed)
y -> IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
and_RDR [LHsExpr (GhcPass 'Parsed)
x,LHsExpr (GhcPass 'Parsed)
y]) [LHsExpr (GhcPass 'Parsed)]
xs
data NullM a =
IsNull
| NotNull
| NullM a
gen_Traversable_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Traversable_binds :: SrcSpan -> TyCon -> (LHsBinds (GhcPass 'Parsed), BagDerivStuff)
gen_Traversable_binds SrcSpan
loc TyCon
tycon
| Role
Phantom <- [Role] -> Role
forall a. [a] -> a
last (TyCon -> [Role]
tyConRoles TyCon
tycon)
= (LHsBind (GhcPass 'Parsed) -> LHsBinds (GhcPass 'Parsed)
forall a. a -> Bag a
unitBag LHsBind (GhcPass 'Parsed)
traverse_bind, BagDerivStuff
forall a. Bag a
emptyBag)
where
traverse_name :: GenLocated SrcSpan RdrName
traverse_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
traverse_RDR
traverse_bind :: LHsBind (GhcPass 'Parsed)
traverse_bind = GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBind GenLocated SrcSpan RdrName
traverse_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
traverse_eqns
traverse_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
traverse_eqns =
[HsMatchContext (NoGhcTc (GhcPass 'Parsed))
-> [LPat (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch HsMatchContext (GhcPass 'Parsed)
HsMatchContext (NoGhcTc (GhcPass 'Parsed))
traverse_match_ctxt
[LPat (GhcPass 'Parsed)
nlWildPat, LPat (GhcPass 'Parsed)
z_Pat]
(IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
pure_RDR [LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
coerce_Expr LHsExpr (GhcPass 'Parsed)
z_Expr])]
traverse_match_ctxt :: HsMatchContext (GhcPass 'Parsed)
traverse_match_ctxt = LIdP (GhcPass 'Parsed) -> HsMatchContext (GhcPass 'Parsed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs GenLocated SrcSpan RdrName
LIdP (GhcPass 'Parsed)
traverse_name
gen_Traversable_binds SrcSpan
loc TyCon
tycon
= (LHsBind (GhcPass 'Parsed) -> LHsBinds (GhcPass 'Parsed)
forall a. a -> Bag a
unitBag LHsBind (GhcPass 'Parsed)
traverse_bind, BagDerivStuff
forall a. Bag a
emptyBag)
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
traverse_name :: GenLocated SrcSpan RdrName
traverse_name = SrcSpan -> RdrName -> GenLocated SrcSpan RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
traverse_RDR
traverse_bind :: LHsBind (GhcPass 'Parsed)
traverse_bind = Int
-> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> GenLocated SrcSpan RdrName
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
-> LHsBind (GhcPass 'Parsed)
mkRdrFunBindEC Int
2 (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
pure_Expr)
GenLocated SrcSpan RdrName
traverse_name [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
traverse_eqns
traverse_eqns :: [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
traverse_eqns = (DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [DataCon]
-> [LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
traverse_eqn [DataCon]
data_cons
traverse_eqn :: DataCon -> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
traverse_eqn DataCon
con
= State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
-> [RdrName]
-> LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))
forall s a. State s a -> s -> a
evalState ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con [LPat (GhcPass 'Parsed)
f_Pat] DataCon
con ([Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts) [RdrName]
bs_RDRs
where
parts :: State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
parts = [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))])
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall a b. (a -> b) -> a -> b
$ FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
-> DataCon -> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
forall a. FFoldType a -> DataCon -> [a]
foldDataConArgs FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_trav DataCon
con
ft_trav :: FFoldType (State [RdrName] (Maybe (LHsExpr GhcPs)))
ft_trav :: FFoldType (State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed))))
ft_trav
= FT :: forall a.
a
-> a
-> a
-> (a -> a -> a)
-> (TyCon -> [a] -> a)
-> (Type -> Type -> a -> a)
-> a
-> (Id -> a -> a)
-> FFoldType a
FT { ft_triv :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_triv = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (LHsExpr (GhcPass 'Parsed))
forall a. Maybe a
Nothing
, ft_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_var = Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
f_Expr)
, ft_tup :: TyCon
-> [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_tup = \TyCon
t [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
gs -> do
[Maybe (LHsExpr (GhcPass 'Parsed))]
gg <- [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
-> State [RdrName] [Maybe (LHsExpr (GhcPass 'Parsed))]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))]
gs
LHsExpr (GhcPass 'Parsed)
lam <- (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
mkSimpleLam ((LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> (LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall a b. (a -> b) -> a -> b
$ ([LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> LHsExpr (GhcPass 'Parsed)
-> State [RdrName] (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a.
Monad m =>
([LPat (GhcPass 'Parsed)]
-> DataCon
-> [a]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> TyCon
-> [a]
-> LHsExpr (GhcPass 'Parsed)
-> m (LHsExpr (GhcPass 'Parsed))
mkSimpleTupleCase [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> State
[RdrName] (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con TyCon
t [Maybe (LHsExpr (GhcPass 'Parsed))]
gg
Maybe (LHsExpr (GhcPass 'Parsed))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed) -> Maybe (LHsExpr (GhcPass 'Parsed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Parsed)
lam)
, ft_ty_app :: Type
-> Type
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_ty_app = \Type
_ Type
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> (LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr (GhcPass 'Parsed)
traverse_Expr) (Maybe (LHsExpr (GhcPass 'Parsed))
-> Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
, ft_forall :: Id
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_forall = \Id
_ State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
g
, ft_co_var :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_co_var = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"contravariant in ft_trav"
, ft_fun :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_fun = String
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
-> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"function in ft_trav"
, ft_bad_app :: State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
ft_bad_app = String -> State [RdrName] (Maybe (LHsExpr (GhcPass 'Parsed)))
forall a. String -> a
panic String
"in other argument in ft_trav" }
match_for_con :: Monad m
=> [LPat GhcPs]
-> DataCon
-> [Maybe (LHsExpr GhcPs)]
-> m (LMatch GhcPs (LHsExpr GhcPs))
match_for_con :: forall (m :: * -> *).
Monad m =>
[LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
match_for_con = HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall (m :: * -> *).
Monad m =>
HsMatchContext (GhcPass 'Parsed)
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
mkSimpleConMatch2 HsMatchContext (GhcPass 'Parsed)
forall p. HsMatchContext p
CaseAlt ((LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed))))
-> (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> m (LHsExpr (GhcPass 'Parsed)))
-> [LPat (GhcPass 'Parsed)]
-> DataCon
-> [Maybe (LHsExpr (GhcPass 'Parsed))]
-> m (LMatch (GhcPass 'Parsed) (LHsExpr (GhcPass 'Parsed)))
forall a b. (a -> b) -> a -> b
$
\LHsExpr (GhcPass 'Parsed)
con [LHsExpr (GhcPass 'Parsed)]
xs -> LHsExpr (GhcPass 'Parsed) -> m (LHsExpr (GhcPass 'Parsed))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkApCon LHsExpr (GhcPass 'Parsed)
con [LHsExpr (GhcPass 'Parsed)]
xs)
where
mkApCon :: LHsExpr GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
mkApCon :: LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
mkApCon LHsExpr (GhcPass 'Parsed)
con [] = IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
pure_RDR [LHsExpr (GhcPass 'Parsed)
con]
mkApCon LHsExpr (GhcPass 'Parsed)
con [LHsExpr (GhcPass 'Parsed)
x] = IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
fmap_RDR [LHsExpr (GhcPass 'Parsed)
con,LHsExpr (GhcPass 'Parsed)
x]
mkApCon LHsExpr (GhcPass 'Parsed)
con (LHsExpr (GhcPass 'Parsed)
x1:LHsExpr (GhcPass 'Parsed)
x2:[LHsExpr (GhcPass 'Parsed)]
xs) =
(LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed))
-> LHsExpr (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)]
-> LHsExpr (GhcPass 'Parsed)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' LHsExpr (GhcPass 'Parsed)
-> LHsExpr (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall {id :: Pass}.
(IsPass id, IdGhcP id ~ RdrName) =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
appAp (IdP (GhcPass 'Parsed)
-> [LHsExpr (GhcPass 'Parsed)] -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass 'Parsed)
liftA2_RDR [LHsExpr (GhcPass 'Parsed)
con,LHsExpr (GhcPass 'Parsed)
x1,LHsExpr (GhcPass 'Parsed)
x2]) [LHsExpr (GhcPass 'Parsed)]
xs
where appAp :: LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
appAp LHsExpr (GhcPass id)
x LHsExpr (GhcPass id)
y = IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
forall (id :: Pass).
IsPass id =>
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass id)
ap_RDR [LHsExpr (GhcPass id)
x,LHsExpr (GhcPass id)
y]
f_Expr, z_Expr, mempty_Expr, foldMap_Expr,
traverse_Expr, coerce_Expr, pure_Expr, true_Expr, false_Expr,
all_Expr, null_Expr :: LHsExpr GhcPs
f_Expr :: LHsExpr (GhcPass 'Parsed)
f_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
f_RDR
z_Expr :: LHsExpr (GhcPass 'Parsed)
z_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
z_RDR
mempty_Expr :: LHsExpr (GhcPass 'Parsed)
mempty_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
mempty_RDR
foldMap_Expr :: LHsExpr (GhcPass 'Parsed)
foldMap_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
foldMap_RDR
traverse_Expr :: LHsExpr (GhcPass 'Parsed)
traverse_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
traverse_RDR
coerce_Expr :: LHsExpr (GhcPass 'Parsed)
coerce_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (Id -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName Id
coerceId)
pure_Expr :: LHsExpr (GhcPass 'Parsed)
pure_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
pure_RDR
true_Expr :: LHsExpr (GhcPass 'Parsed)
true_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
true_RDR
false_Expr :: LHsExpr (GhcPass 'Parsed)
false_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
false_RDR
all_Expr :: LHsExpr (GhcPass 'Parsed)
all_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
all_RDR
null_Expr :: LHsExpr (GhcPass 'Parsed)
null_Expr = IdP (GhcPass 'Parsed) -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass 'Parsed)
null_RDR
f_RDR, z_RDR :: RdrName
f_RDR :: RdrName
f_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit String
"f")
z_RDR :: RdrName
z_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit String
"z")
as_RDRs, bs_RDRs :: [RdrName]
as_RDRs :: [RdrName]
as_RDRs = [ FastString -> RdrName
mkVarUnqual (String -> FastString
mkFastString (String
"a"String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i)) | Int
i <- [(Int
1::Int) .. ] ]
bs_RDRs :: [RdrName]
bs_RDRs = [ FastString -> RdrName
mkVarUnqual (String -> FastString
mkFastString (String
"b"String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i)) | Int
i <- [(Int
1::Int) .. ] ]
as_Vars, bs_Vars :: [LHsExpr GhcPs]
as_Vars :: [LHsExpr (GhcPass 'Parsed)]
as_Vars = (RdrName -> LHsExpr (GhcPass 'Parsed))
-> [RdrName] -> [LHsExpr (GhcPass 'Parsed)]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar [RdrName]
as_RDRs
bs_Vars :: [LHsExpr (GhcPass 'Parsed)]
bs_Vars = (RdrName -> LHsExpr (GhcPass 'Parsed))
-> [RdrName] -> [LHsExpr (GhcPass 'Parsed)]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> LHsExpr (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar [RdrName]
bs_RDRs
f_Pat, z_Pat :: LPat GhcPs
f_Pat :: LPat (GhcPass 'Parsed)
f_Pat = IdP (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat RdrName
IdP (GhcPass 'Parsed)
f_RDR
z_Pat :: LPat (GhcPass 'Parsed)
z_Pat = IdP (GhcPass 'Parsed) -> LPat (GhcPass 'Parsed)
forall (id :: Pass). IdP (GhcPass id) -> LPat (GhcPass id)
nlVarPat RdrName
IdP (GhcPass 'Parsed)
z_RDR