Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.Haskell.Tools.Rewrite.Create.Decls
Contents
Description
Generation of declaration-level AST fragments for refactorings.
The bindings defined here create a the annotated version of the AST constructor with the same name.
For example, mkTypeSignature
creates the annotated version of the UTypeSignature
AST constructor.
Synopsis
- mkTypeDecl :: DeclHead -> Type -> Decl
- mkStandaloneDeriving :: Maybe DeriveStrategy -> Maybe OverlapPragma -> InstanceRule -> Decl
- mkFixityDecl :: FixitySignature -> Decl
- mkDefaultDecl :: [Type] -> Decl
- mkTypeSigDecl :: TypeSignature -> Decl
- mkValueBinding :: ValueBind -> Decl
- mkSpliceDecl :: Splice -> Decl
- mkDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> [ConDecl] -> [Deriving] -> Decl
- mkGADTDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> Decl
- mkGadtConDecl :: [Name] -> Type -> GadtConDecl
- mkGadtRecordConDecl :: [Name] -> [FieldDecl] -> Type -> GadtConDecl
- mkConDecl :: Name -> [Type] -> ConDecl
- mkRecordConDecl :: Name -> [FieldDecl] -> ConDecl
- mkInfixConDecl :: Type -> Operator -> Type -> ConDecl
- mkFieldDecl :: [Name] -> Type -> FieldDecl
- mkDeriving :: [InstanceHead] -> Deriving
- mkDataKeyword :: DataOrNewtypeKeyword
- mkNewtypeKeyword :: DataOrNewtypeKeyword
- mkClassDecl :: Maybe Context -> DeclHead -> [FunDep] -> Maybe ClassBody -> Decl
- mkClassBody :: [ClassElement] -> ClassBody
- mkClassElemSig :: TypeSignature -> ClassElement
- mkClassElemDef :: ValueBind -> ClassElement
- mkClassElemTypeFam :: DeclHead -> Maybe TypeFamilySpec -> ClassElement
- mkClassElemDataFam :: DeclHead -> Maybe KindConstraint -> ClassElement
- mkClsDefaultType :: DeclHead -> Type -> ClassElement
- mkClsDefaultSig :: Name -> Type -> ClassElement
- mkFunDep :: [Name] -> [Name] -> FunDep
- mkClsMinimal :: MinimalFormula -> ClassElement
- mkMinimalName :: Name -> MinimalFormula
- mkMinimalParen :: MinimalFormula -> MinimalFormula
- mkMinimalOr :: [MinimalFormula] -> MinimalFormula
- mkMinimalAnd :: [MinimalFormula] -> MinimalFormula
- mkNameDeclHead :: Name -> DeclHead
- mkParenDeclHead :: DeclHead -> DeclHead
- mkDeclHeadApp :: DeclHead -> TyVar -> DeclHead
- mkInfixDeclHead :: TyVar -> Operator -> TyVar -> DeclHead
- mkInstanceDecl :: Maybe OverlapPragma -> InstanceRule -> Maybe InstBody -> Decl
- mkInstanceRule :: Maybe Context -> InstanceHead -> InstanceRule
- mkInstanceHead :: Name -> InstanceHead
- mkInfixInstanceHead :: Type -> Operator -> InstanceHead
- mkParenInstanceHead :: InstanceHead -> InstanceHead
- mkAppInstanceHead :: InstanceHead -> Type -> InstanceHead
- mkInstanceBody :: [InstBodyDecl] -> InstBody
- mkInstanceBind :: ValueBind -> InstBodyDecl
- mkInstanceTypeSig :: TypeSignature -> InstBodyDecl
- mkInstanceTypeFamilyDef :: TypeEqn -> InstBodyDecl
- mkInstanceDataFamilyDef :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> InstBodyDecl
- mkInstanceDataFamilyGADTDef :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> InstBodyDecl
- mkInstanceSpecializePragma :: Type -> InstBodyDecl
- mkEnableOverlap :: OverlapPragma
- mkDisableOverlap :: OverlapPragma
- mkOverlappable :: OverlapPragma
- mkOverlapping :: OverlapPragma
- mkOverlaps :: OverlapPragma
- mkIncoherentOverlap :: OverlapPragma
- mkRoleDecl :: QualifiedName -> [Role] -> Decl
- mkNominalRole :: Role
- mkRepresentationalRole :: Role
- mkPhantomRole :: Role
- mkForeignImport :: CallConv -> Maybe Safety -> Name -> Type -> Decl
- mkForeignExport :: CallConv -> Name -> Type -> Decl
- mkStdCall :: CallConv
- mkCCall :: CallConv
- mkCApi :: CallConv
- mkUnsafe :: Safety
- mkTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> Decl
- mkClosedTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> [TypeEqn] -> Decl
- mkDataFamily :: DeclHead -> Maybe KindConstraint -> Decl
- mkTypeFamilyKindSpec :: KindConstraint -> TypeFamilySpec
- mkTypeFamilyInjectivitySpec :: TyVar -> [Name] -> TypeFamilySpec
- mkTypeEqn :: Type -> Type -> TypeEqn
- mkTypeInstance :: InstanceRule -> Type -> Decl
- mkDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> Decl
- mkGadtDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> Decl
- mkPatternSynonym :: PatSynLhs -> PatSynRhs -> Decl
- mkConPatSyn :: Name -> [Name] -> PatSynLhs
- mkInfixPatSyn :: Name -> Operator -> Name -> PatSynLhs
- mkRecordPatSyn :: Name -> [Name] -> PatSynLhs
- mkSymmetricPatSyn :: Pattern -> PatSynRhs
- mkOneWayPatSyn :: Pattern -> PatSynRhs
- mkTwoWayPatSyn :: Pattern -> [Match] -> PatSynRhs
- mkPatternSignatureDecl :: PatternSignature -> Decl
- mkPatternSignature :: [Name] -> Type -> PatternSignature
- mkPragmaDecl :: TopLevelPragma -> Decl
- mkRulePragma :: [Rule] -> TopLevelPragma
- mkDeprPragma :: [Name] -> String -> TopLevelPragma
- mkWarningPragma :: [Name] -> String -> TopLevelPragma
- mkAnnPragma :: AnnotationSubject -> Expr -> TopLevelPragma
- mkInlinePragma :: Maybe ConlikeAnnot -> Maybe PhaseControl -> Name -> TopLevelPragma
- mkNoInlinePragma :: Name -> TopLevelPragma
- mkInlinablePragma :: Maybe PhaseControl -> Name -> TopLevelPragma
- mkLinePragma :: Int -> Maybe StringNode -> TopLevelPragma
- mkSpecializePragma :: Maybe PhaseControl -> Name -> [Type] -> TopLevelPragma
- mkPhaseControlFrom :: Integer -> PhaseControl
- mkPhaseControlUntil :: Integer -> PhaseControl
- mkRewriteRule :: String -> Maybe PhaseControl -> [RuleVar] -> Expr -> Expr -> Rule
- mkRuleVar :: Name -> RuleVar
- mkNameAnnotation :: Name -> AnnotationSubject
- mkTypeAnnotation :: Name -> AnnotationSubject
- mkModuleAnnotation :: AnnotationSubject
- mkConlikeAnnotation :: ConlikeAnnot
Documentation
mkStandaloneDeriving :: Maybe DeriveStrategy -> Maybe OverlapPragma -> InstanceRule -> Decl Source #
Creates a standalone deriving declaration ( deriving instance X T
)
mkFixityDecl :: FixitySignature -> Decl Source #
Creates a fixity declaration ( infixl 5 +, -
)
mkDefaultDecl :: [Type] -> Decl Source #
Creates default types ( default (T1, T2)
)
mkTypeSigDecl :: TypeSignature -> Decl Source #
Creates type signature declaration ( f :: Int -> Int
)
mkValueBinding :: ValueBind -> Decl Source #
Creates a function or value binding ( f x = 12
)
mkSpliceDecl :: Splice -> Decl Source #
Creates a Template Haskell splice declaration ( $(generateDecls)
)
Data type definitions
mkDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> [ConDecl] -> [Deriving] -> Decl Source #
Creates a data or newtype declaration.
mkGADTDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> Decl Source #
Creates a GADT-style data or newtype declaration.
mkGadtConDecl :: [Name] -> Type -> GadtConDecl Source #
Creates a GADT constructor declaration ( D1 :: Int -> T String
)
mkGadtRecordConDecl :: [Name] -> [FieldDecl] -> Type -> GadtConDecl Source #
Creates a GADT constructor declaration with record syntax ( D1 :: { val :: Int } -> T String
)
mkRecordConDecl :: Name -> [FieldDecl] -> ConDecl Source #
Creates a record data constructor ( Point { x :: Double, y :: Double }
)
mkInfixConDecl :: Type -> Operator -> Type -> ConDecl Source #
Creates an infix data constructor ( t1 :+: t2
)
mkFieldDecl :: [Name] -> Type -> FieldDecl Source #
Creates a field declaration ( fld :: Int
) for a constructor
mkDeriving :: [InstanceHead] -> Deriving Source #
Creates a deriving clause following a data type declaration. ( deriving Show
or deriving (Show, Eq)
)
mkDataKeyword :: DataOrNewtypeKeyword Source #
The data
keyword in a type definition
mkNewtypeKeyword :: DataOrNewtypeKeyword Source #
The newtype
keyword in a type definition
Class declarations
mkClassDecl :: Maybe Context -> DeclHead -> [FunDep] -> Maybe ClassBody -> Decl Source #
Creates a type class declaration ( class X a where f = ...
)
mkClassBody :: [ClassElement] -> ClassBody Source #
Creates the list of declarations that can appear in a typeclass
mkClassElemSig :: TypeSignature -> ClassElement Source #
Creates a type signature as class element: f :: A -> B
mkClassElemDef :: ValueBind -> ClassElement Source #
Creates a default binding as class element: f x = "aaa"
mkClassElemTypeFam :: DeclHead -> Maybe TypeFamilySpec -> ClassElement Source #
Creates an associated type synonym in class: type T y :: *
mkClassElemDataFam :: DeclHead -> Maybe KindConstraint -> ClassElement Source #
Creates an associated data synonym in class: data T y :: *
mkClsDefaultType :: DeclHead -> Type -> ClassElement Source #
Creates a default choice for type synonym in class: type T x = TE
or type instance T x = TE
mkClsDefaultSig :: Name -> Type -> ClassElement Source #
Creates a default signature (by using DefaultSignatures
) in class: default enum :: (Generic a, GEnum (Rep a)) => [a]
mkFunDep :: [Name] -> [Name] -> FunDep Source #
Creates a functional dependency, given on the form l1 ... ln -> r1 ... rn
mkClsMinimal :: MinimalFormula -> ClassElement Source #
Minimal pragma: {-# MINIMAL (==) | (/=) #-}
in a class
mkMinimalName :: Name -> MinimalFormula Source #
mkMinimalOr :: [MinimalFormula] -> MinimalFormula Source #
One of the minimal formulas are needed ( min1 | min2
)
mkMinimalAnd :: [MinimalFormula] -> MinimalFormula Source #
Both of the minimal formulas are needed ( min1 , min2
)
Declaration heads
mkNameDeclHead :: Name -> DeclHead Source #
Type or class name as a declaration head
mkParenDeclHead :: DeclHead -> DeclHead Source #
Parenthesized type as a declaration head
mkInfixDeclHead :: TyVar -> Operator -> TyVar -> DeclHead Source #
Infix application of the type/class name to the left operand in a declaration head
Type class instance declarations
mkInstanceDecl :: Maybe OverlapPragma -> InstanceRule -> Maybe InstBody -> Decl Source #
Creates a type class instance declaration ( instance X T [where f = ...]
)
mkInstanceRule :: Maybe Context -> InstanceHead -> InstanceRule Source #
The instance declaration rule, which is, roughly, the part of the instance declaration before the where keyword.
mkInstanceHead :: Name -> InstanceHead Source #
Type or class name as a part of the instance declaration
mkInfixInstanceHead :: Type -> Operator -> InstanceHead Source #
Infix application of the type/class name to the left operand as a part of the instance declaration
mkParenInstanceHead :: InstanceHead -> InstanceHead Source #
Parenthesized instance head as a part of the instance declaration
mkAppInstanceHead :: InstanceHead -> Type -> InstanceHead Source #
Application to one more type as a part of the instance declaration
mkInstanceBody :: [InstBodyDecl] -> InstBody Source #
Instance body is the implementation of the class functions ( where a x = 1; b x = 2
)
mkInstanceBind :: ValueBind -> InstBodyDecl Source #
A normal declaration ( f x = 12
) in a type class instance
mkInstanceTypeSig :: TypeSignature -> InstBodyDecl Source #
Type signature in instance definition with InstanceSigs
mkInstanceTypeFamilyDef :: TypeEqn -> InstBodyDecl Source #
An associated type definition ( type A X = B
) in a type class instance
mkInstanceDataFamilyDef :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> InstBodyDecl Source #
An associated data type implementation ( data A X = C1 | C2
) int a type class instance
mkInstanceDataFamilyGADTDef :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> InstBodyDecl Source #
An associated data type implemented using GADT style int a type class instance
mkInstanceSpecializePragma :: Type -> InstBodyDecl Source #
Specialize instance pragma (no phase selection is allowed) in a type class instance
mkEnableOverlap :: OverlapPragma Source #
OVERLAP
pragma for type instance definitions
mkDisableOverlap :: OverlapPragma Source #
NO_OVERLAP
pragma for type instance definitions
mkOverlappable :: OverlapPragma Source #
OVERLAPPABLE
pragma for type instance definitions
mkOverlapping :: OverlapPragma Source #
OVERLAPPING
pragma for type instance definitions
mkOverlaps :: OverlapPragma Source #
OVERLAPS
pragma for type instance definitions
mkIncoherentOverlap :: OverlapPragma Source #
INCOHERENT
pragma for type instance definitions
Type roles
mkRoleDecl :: QualifiedName -> [Role] -> Decl Source #
Creates a role annotations ( type role Ptr representational
)
mkNominalRole :: Role Source #
Marks a given type parameter as nominal
.
mkRepresentationalRole :: Role Source #
Marks a given type parameter as representational
.
mkPhantomRole :: Role Source #
Marks a given type parameter as phantom
.
Foreign imports and exports
mkForeignImport :: CallConv -> Maybe Safety -> Name -> Type -> Decl Source #
Creates a foreign import ( foreign import foo :: Int -> IO Int
)
mkForeignExport :: CallConv -> Name -> Type -> Decl Source #
Creates a foreign export ( foreign export ccall foo :: Int -> IO Int
)
Type and data families
mkTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> Decl Source #
Creates a type family declaration ( type family F x
)
mkClosedTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> [TypeEqn] -> Decl Source #
Creates a closed type family declaration ( type family F x where F Int = (); F a = Int
)
mkDataFamily :: DeclHead -> Maybe KindConstraint -> Decl Source #
Creates a data family declaration ( data family A a :: * -> *
)
mkTypeFamilyKindSpec :: KindConstraint -> TypeFamilySpec Source #
Specifies the kind of a type family ( :: * -> *
)
mkTypeFamilyInjectivitySpec :: TyVar -> [Name] -> TypeFamilySpec Source #
Specifies the injectivity of a type family ( = r | r -> a
)
mkTypeEqn :: Type -> Type -> TypeEqn Source #
Type equations as found in closed type families ( T A = S
)
mkTypeInstance :: InstanceRule -> Type -> Decl Source #
Creates a type family instance declaration ( type instance Fam T = AssignedT
)
mkDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> Decl Source #
Creates a data instance declaration ( data instance Fam T = Con1 | Con2
)
mkGadtDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> Decl Source #
Creates a GADT-style data instance declaration ( data instance Fam T where ...
)
Pattern synonyms
mkPatternSynonym :: PatSynLhs -> PatSynRhs -> Decl Source #
Creates a pattern synonym ( pattern Arrow t1 t2 = App "->" [t1, t2]
)
mkConPatSyn :: Name -> [Name] -> PatSynLhs Source #
Creates a left hand side of a pattern synonym with a constructor name and arguments ( Arrow t1 t2
)
mkInfixPatSyn :: Name -> Operator -> Name -> PatSynLhs Source #
Creates an infix pattern synonym left-hand side ( t1 :+: t2
)
mkRecordPatSyn :: Name -> [Name] -> PatSynLhs Source #
Creates a record-style pattern synonym left-hand side ( Arrow { arrowFrom, arrowTo }
)
mkSymmetricPatSyn :: Pattern -> PatSynRhs Source #
Creates an automatically two-way pattern synonym ( = App "Int" []
)
mkOneWayPatSyn :: Pattern -> PatSynRhs Source #
Creates a pattern synonym that can be only used for pattenr matching but not for combining ( <- App "Int" []
)
mkTwoWayPatSyn :: Pattern -> [Match] -> PatSynRhs Source #
Creates a pattern synonym with the other direction explicitly specified ( <- App "Int" [] where Int = App "Int" []
)
mkPatternSignatureDecl :: PatternSignature -> Decl Source #
Creates a pattern type signature declaration ( pattern Succ :: Int -> Int
)
mkPatternSignature :: [Name] -> Type -> PatternSignature Source #
Top level pragmas
mkPragmaDecl :: TopLevelPragma -> Decl Source #
Creates a top-level pragmas
mkRulePragma :: [Rule] -> TopLevelPragma Source #
A pragma that introduces source rewrite rules ( {-# RULES "map/map" [2] forall f g xs. map f (map g xs) = map (f.g) xs #-}
)
mkDeprPragma :: [Name] -> String -> TopLevelPragma Source #
A pragma that marks definitions as deprecated ( {-# DEPRECATED f "f will be replaced by g" #-}
)
mkWarningPragma :: [Name] -> String -> TopLevelPragma Source #
A pragma that marks definitions as deprecated ( {-# WARNING unsafePerformIO "you should know what you are doing" #-}
)
mkAnnPragma :: AnnotationSubject -> Expr -> TopLevelPragma Source #
A pragma that annotates a definition with an arbitrary value ( {-# ANN f 42 #-}
)
mkInlinePragma :: Maybe ConlikeAnnot -> Maybe PhaseControl -> Name -> TopLevelPragma Source #
A pragma that marks a function for inlining to the compiler ( {-# INLINE thenUs #-}
)
mkNoInlinePragma :: Name -> TopLevelPragma Source #
A pragma that forbids a function from being inlined by the compiler ( {-# NOINLINE f #-}
)
mkInlinablePragma :: Maybe PhaseControl -> Name -> TopLevelPragma Source #
A pragma that marks a function that it may be inlined by the compiler ( {-# INLINABLE thenUs #-}
)
mkLinePragma :: Int -> Maybe StringNode -> TopLevelPragma Source #
A pragma for maintaining line numbers in generated sources ( {-# LINE 123 "somefile" #-}
)
mkSpecializePragma :: Maybe PhaseControl -> Name -> [Type] -> TopLevelPragma Source #
A pragma that tells the compiler that a polymorph function should be optimized for a given type ( {-# SPECIALISE f :: Int -> b -> b #-}
)
mkPhaseControlFrom :: Integer -> PhaseControl Source #
Marks that the pragma should be applied from a given compile phase ( [2]
)
mkPhaseControlUntil :: Integer -> PhaseControl Source #
Marks that the pragma should be applied until a given compile phase ( [~2]
)
mkRewriteRule :: String -> Maybe PhaseControl -> [RuleVar] -> Expr -> Expr -> Rule Source #
A rewrite rule ( "map/map" forall f g xs. map f (map g xs) = map (f.g) xs
)
mkNameAnnotation :: Name -> AnnotationSubject Source #
The definition with the given name is annotated
mkTypeAnnotation :: Name -> AnnotationSubject Source #
A type with the given name is annotated
mkModuleAnnotation :: AnnotationSubject Source #
The whole module is annotated
mkConlikeAnnotation :: ConlikeAnnot Source #
A CONLIKE
modifier for an INLINE
pragma.