haskell-tools-rewrite-1.1.1.0: Facilities for generating new parts of the Haskell-Tools AST

Safe HaskellNone
LanguageHaskell2010

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

Documentation

mkTypeDecl :: DeclHead -> Type -> Decl Source #

Creates a type synonym ( type String = [Char] )

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 )

mkConDecl :: Name -> [Type] -> ConDecl Source #

Creates an ordinary data constructor ( C t1 t2 )

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

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

mkDeclHeadApp :: DeclHead -> TyVar -> DeclHead Source #

Application in 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 )

mkStdCall :: CallConv Source #

Specifies stdcall calling convention for foreign import/export.

mkCCall :: CallConv Source #

Specifies ccall calling convention for foreign import/export.

mkCApi :: CallConv Source #

Specifies capi calling convention for foreign import/export.

mkUnsafe :: Safety Source #

Specifies that the given foreign import is unsafe.

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 )

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.