{-# LANGUAGE CPP #-}
module ConLike (
ConLike(..)
, conLikeArity
, conLikeFieldLabels
, conLikeInstOrigArgTys
, conLikeExTyCoVars
, conLikeName
, conLikeStupidTheta
, conLikeWrapId_maybe
, conLikeImplBangs
, conLikeFullSig
, conLikeResTy
, conLikeFieldType
, conLikesWithFields
, conLikeIsInfix
) where
#include "HsVersions.h"
import GhcPrelude
import DataCon
import PatSyn
import Outputable
import Unique
import Util
import Name
import BasicTypes
import TyCoRep (Type, ThetaType)
import Var
import Type (mkTyConApp)
import qualified Data.Data as Data
data ConLike = RealDataCon DataCon
| PatSynCon PatSyn
instance Eq ConLike where
== :: ConLike -> ConLike -> Bool
(==) = ConLike -> ConLike -> Bool
eqConLike
eqConLike :: ConLike -> ConLike -> Bool
eqConLike :: ConLike -> ConLike -> Bool
eqConLike x :: ConLike
x y :: ConLike
y = ConLike -> Unique
forall a. Uniquable a => a -> Unique
getUnique ConLike
x Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== ConLike -> Unique
forall a. Uniquable a => a -> Unique
getUnique ConLike
y
instance Uniquable ConLike where
getUnique :: ConLike -> Unique
getUnique (RealDataCon dc :: DataCon
dc) = DataCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique DataCon
dc
getUnique (PatSynCon ps :: PatSyn
ps) = PatSyn -> Unique
forall a. Uniquable a => a -> Unique
getUnique PatSyn
ps
instance NamedThing ConLike where
getName :: ConLike -> Name
getName (RealDataCon dc :: DataCon
dc) = DataCon -> Name
forall a. NamedThing a => a -> Name
getName DataCon
dc
getName (PatSynCon ps :: PatSyn
ps) = PatSyn -> Name
forall a. NamedThing a => a -> Name
getName PatSyn
ps
instance Outputable ConLike where
ppr :: ConLike -> SDoc
ppr (RealDataCon dc :: DataCon
dc) = DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr DataCon
dc
ppr (PatSynCon ps :: PatSyn
ps) = PatSyn -> SDoc
forall a. Outputable a => a -> SDoc
ppr PatSyn
ps
instance OutputableBndr ConLike where
pprInfixOcc :: ConLike -> SDoc
pprInfixOcc (RealDataCon dc :: DataCon
dc) = DataCon -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc DataCon
dc
pprInfixOcc (PatSynCon ps :: PatSyn
ps) = PatSyn -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc PatSyn
ps
pprPrefixOcc :: ConLike -> SDoc
pprPrefixOcc (RealDataCon dc :: DataCon
dc) = DataCon -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc DataCon
dc
pprPrefixOcc (PatSynCon ps :: PatSyn
ps) = PatSyn -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc PatSyn
ps
instance Data.Data ConLike where
toConstr :: ConLike -> Constr
toConstr _ = String -> Constr
abstractConstr "ConLike"
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConLike
gunfold _ _ = String -> Constr -> c ConLike
forall a. HasCallStack => String -> a
error "gunfold"
dataTypeOf :: ConLike -> DataType
dataTypeOf _ = String -> DataType
mkNoRepType "ConLike"
conLikeArity :: ConLike -> Arity
conLikeArity :: ConLike -> Int
conLikeArity (RealDataCon data_con :: DataCon
data_con) = DataCon -> Int
dataConSourceArity DataCon
data_con
conLikeArity (PatSynCon pat_syn :: PatSyn
pat_syn) = PatSyn -> Int
patSynArity PatSyn
pat_syn
conLikeFieldLabels :: ConLike -> [FieldLabel]
conLikeFieldLabels :: ConLike -> [FieldLabel]
conLikeFieldLabels (RealDataCon data_con :: DataCon
data_con) = DataCon -> [FieldLabel]
dataConFieldLabels DataCon
data_con
conLikeFieldLabels (PatSynCon pat_syn :: PatSyn
pat_syn) = PatSyn -> [FieldLabel]
patSynFieldLabels PatSyn
pat_syn
conLikeInstOrigArgTys :: ConLike -> [Type] -> [Type]
conLikeInstOrigArgTys :: ConLike -> [Type] -> [Type]
conLikeInstOrigArgTys (RealDataCon data_con :: DataCon
data_con) tys :: [Type]
tys =
DataCon -> [Type] -> [Type]
dataConInstOrigArgTys DataCon
data_con [Type]
tys
conLikeInstOrigArgTys (PatSynCon pat_syn :: PatSyn
pat_syn) tys :: [Type]
tys =
PatSyn -> [Type] -> [Type]
patSynInstArgTys PatSyn
pat_syn [Type]
tys
conLikeExTyCoVars :: ConLike -> [TyCoVar]
conLikeExTyCoVars :: ConLike -> [TyCoVar]
conLikeExTyCoVars (RealDataCon dcon1 :: DataCon
dcon1) = DataCon -> [TyCoVar]
dataConExTyCoVars DataCon
dcon1
conLikeExTyCoVars (PatSynCon psyn1 :: PatSyn
psyn1) = PatSyn -> [TyCoVar]
patSynExTyVars PatSyn
psyn1
conLikeName :: ConLike -> Name
conLikeName :: ConLike -> Name
conLikeName (RealDataCon data_con :: DataCon
data_con) = DataCon -> Name
dataConName DataCon
data_con
conLikeName (PatSynCon pat_syn :: PatSyn
pat_syn) = PatSyn -> Name
patSynName PatSyn
pat_syn
conLikeStupidTheta :: ConLike -> ThetaType
conLikeStupidTheta :: ConLike -> [Type]
conLikeStupidTheta (RealDataCon data_con :: DataCon
data_con) = DataCon -> [Type]
dataConStupidTheta DataCon
data_con
conLikeStupidTheta (PatSynCon {}) = []
conLikeWrapId_maybe :: ConLike -> Maybe Id
conLikeWrapId_maybe :: ConLike -> Maybe TyCoVar
conLikeWrapId_maybe (RealDataCon data_con :: DataCon
data_con) = TyCoVar -> Maybe TyCoVar
forall a. a -> Maybe a
Just (TyCoVar -> Maybe TyCoVar) -> TyCoVar -> Maybe TyCoVar
forall a b. (a -> b) -> a -> b
$ DataCon -> TyCoVar
dataConWrapId DataCon
data_con
conLikeWrapId_maybe (PatSynCon pat_syn :: PatSyn
pat_syn) = (TyCoVar, Bool) -> TyCoVar
forall a b. (a, b) -> a
fst ((TyCoVar, Bool) -> TyCoVar)
-> Maybe (TyCoVar, Bool) -> Maybe TyCoVar
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatSyn -> Maybe (TyCoVar, Bool)
patSynBuilder PatSyn
pat_syn
conLikeImplBangs :: ConLike -> [HsImplBang]
conLikeImplBangs :: ConLike -> [HsImplBang]
conLikeImplBangs (RealDataCon data_con :: DataCon
data_con) = DataCon -> [HsImplBang]
dataConImplBangs DataCon
data_con
conLikeImplBangs (PatSynCon pat_syn :: PatSyn
pat_syn) =
Int -> HsImplBang -> [HsImplBang]
forall a. Int -> a -> [a]
replicate (PatSyn -> Int
patSynArity PatSyn
pat_syn) HsImplBang
HsLazy
conLikeResTy :: ConLike -> [Type] -> Type
conLikeResTy :: ConLike -> [Type] -> Type
conLikeResTy (RealDataCon con :: DataCon
con) tys :: [Type]
tys = TyCon -> [Type] -> Type
mkTyConApp (DataCon -> TyCon
dataConTyCon DataCon
con) [Type]
tys
conLikeResTy (PatSynCon ps :: PatSyn
ps) tys :: [Type]
tys = PatSyn -> [Type] -> Type
patSynInstResTy PatSyn
ps [Type]
tys
conLikeFullSig :: ConLike
-> ([TyVar], [TyCoVar], [EqSpec]
, ThetaType, ThetaType, [Type], Type)
conLikeFullSig :: ConLike
-> ([TyCoVar], [TyCoVar], [EqSpec], [Type], [Type], [Type], Type)
conLikeFullSig (RealDataCon con :: DataCon
con) =
let (univ_tvs :: [TyCoVar]
univ_tvs, ex_tvs :: [TyCoVar]
ex_tvs, eq_spec :: [EqSpec]
eq_spec, theta :: [Type]
theta, arg_tys :: [Type]
arg_tys, res_ty :: Type
res_ty) = DataCon -> ([TyCoVar], [TyCoVar], [EqSpec], [Type], [Type], Type)
dataConFullSig DataCon
con
in ([TyCoVar]
univ_tvs, [TyCoVar]
ex_tvs, [EqSpec]
eq_spec, [Type]
theta, [], [Type]
arg_tys, Type
res_ty)
conLikeFullSig (PatSynCon pat_syn :: PatSyn
pat_syn) =
let (univ_tvs :: [TyCoVar]
univ_tvs, req :: [Type]
req, ex_tvs :: [TyCoVar]
ex_tvs, prov :: [Type]
prov, arg_tys :: [Type]
arg_tys, res_ty :: Type
res_ty) = PatSyn -> ([TyCoVar], [Type], [TyCoVar], [Type], [Type], Type)
patSynSig PatSyn
pat_syn
in ([TyCoVar]
univ_tvs, [TyCoVar]
ex_tvs, [], [Type]
prov, [Type]
req, [Type]
arg_tys, Type
res_ty)
conLikeFieldType :: ConLike -> FieldLabelString -> Type
conLikeFieldType :: ConLike -> FieldLabelString -> Type
conLikeFieldType (PatSynCon ps :: PatSyn
ps) label :: FieldLabelString
label = PatSyn -> FieldLabelString -> Type
patSynFieldType PatSyn
ps FieldLabelString
label
conLikeFieldType (RealDataCon dc :: DataCon
dc) label :: FieldLabelString
label = DataCon -> FieldLabelString -> Type
dataConFieldType DataCon
dc FieldLabelString
label
conLikesWithFields :: [ConLike] -> [FieldLabelString] -> [ConLike]
conLikesWithFields :: [ConLike] -> [FieldLabelString] -> [ConLike]
conLikesWithFields con_likes :: [ConLike]
con_likes lbls :: [FieldLabelString]
lbls = (ConLike -> Bool) -> [ConLike] -> [ConLike]
forall a. (a -> Bool) -> [a] -> [a]
filter ConLike -> Bool
has_flds [ConLike]
con_likes
where has_flds :: ConLike -> Bool
has_flds dc :: ConLike
dc = (FieldLabelString -> Bool) -> [FieldLabelString] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (ConLike -> FieldLabelString -> Bool
has_fld ConLike
dc) [FieldLabelString]
lbls
has_fld :: ConLike -> FieldLabelString -> Bool
has_fld dc :: ConLike
dc lbl :: FieldLabelString
lbl = (FieldLabel -> Bool) -> [FieldLabel] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\ fl :: FieldLabel
fl -> FieldLabel -> FieldLabelString
forall a. FieldLbl a -> FieldLabelString
flLabel FieldLabel
fl FieldLabelString -> FieldLabelString -> Bool
forall a. Eq a => a -> a -> Bool
== FieldLabelString
lbl) (ConLike -> [FieldLabel]
conLikeFieldLabels ConLike
dc)
conLikeIsInfix :: ConLike -> Bool
conLikeIsInfix :: ConLike -> Bool
conLikeIsInfix (RealDataCon dc :: DataCon
dc) = DataCon -> Bool
dataConIsInfix DataCon
dc
conLikeIsInfix (PatSynCon ps :: PatSyn
ps) = PatSyn -> Bool
patSynIsInfix PatSyn
ps