haskell-tools-rewrite-1.1.0.1: 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 #

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

mkStandaloneDeriving :: Maybe DeriveStrategy -> Maybe OverlapPragma -> InstanceRule -> Decl #

Creates a standalone deriving declaration ( deriving instance X T )

mkFixityDecl :: FixitySignature -> Decl #

Creates a fixity declaration ( infixl 5 +, - )

mkDefaultDecl :: [Type] -> Decl #

Creates default types ( default (T1, T2) )

mkTypeSigDecl :: TypeSignature -> Decl #

Creates type signature declaration ( f :: Int -> Int )

mkValueBinding :: ValueBind -> Decl #

Creates a function or value binding ( f x = 12 )

mkSpliceDecl :: Splice -> Decl #

Creates a Template Haskell splice declaration ( $(generateDecls) )

Data type definitions

mkDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> [ConDecl] -> [Deriving] -> Decl #

Creates a data or newtype declaration.

mkGADTDataDecl :: DataOrNewtypeKeyword -> Maybe Context -> DeclHead -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> Decl #

Creates a GADT-style data or newtype declaration.

mkGadtConDecl :: [Name] -> Type -> GadtConDecl #

Creates a GADT constructor declaration ( D1 :: Int -> T String )

mkGadtRecordConDecl :: [Name] -> [FieldDecl] -> Type -> GadtConDecl #

Creates a GADT constructor declaration with record syntax ( D1 :: { val :: Int } -> T String )

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

Creates an ordinary data constructor ( C t1 t2 )

mkRecordConDecl :: Name -> [FieldDecl] -> ConDecl #

Creates a record data constructor ( Point { x :: Double, y :: Double } )

mkInfixConDecl :: Type -> Operator -> Type -> ConDecl #

Creates an infix data constructor ( t1 :+: t2 )

mkFieldDecl :: [Name] -> Type -> FieldDecl #

Creates a field declaration ( fld :: Int ) for a constructor

mkDeriving :: [InstanceHead] -> Deriving #

Creates a deriving clause following a data type declaration. ( deriving Show or deriving (Show, Eq) )

mkDataKeyword :: DataOrNewtypeKeyword #

The data keyword in a type definition

mkNewtypeKeyword :: DataOrNewtypeKeyword #

The newtype keyword in a type definition

Class declarations

mkClassDecl :: Maybe Context -> DeclHead -> [FunDep] -> Maybe ClassBody -> Decl #

Creates a type class declaration ( class X a where f = ... )

mkClassBody :: [ClassElement] -> ClassBody #

Creates the list of declarations that can appear in a typeclass

mkClassElemSig :: TypeSignature -> ClassElement #

Creates a type signature as class element: f :: A -> B

mkClassElemDef :: ValueBind -> ClassElement #

Creates a default binding as class element: f x = "aaa"

mkClassElemTypeFam :: DeclHead -> Maybe TypeFamilySpec -> ClassElement #

Creates an associated type synonym in class: type T y :: *

mkClassElemDataFam :: DeclHead -> Maybe KindConstraint -> ClassElement #

Creates an associated data synonym in class: data T y :: *

mkClsDefaultType :: DeclHead -> Type -> ClassElement #

Creates a default choice for type synonym in class: type T x = TE or type instance T x = TE

mkClsDefaultSig :: Name -> Type -> ClassElement #

Creates a default signature (by using DefaultSignatures) in class: default enum :: (Generic a, GEnum (Rep a)) => [a]

mkFunDep :: [Name] -> [Name] -> FunDep #

Creates a functional dependency, given on the form l1 ... ln -> r1 ... rn

mkClsMinimal :: MinimalFormula -> ClassElement #

Minimal pragma: {-# MINIMAL (==) | (/=) #-} in a class

mkMinimalOr :: [MinimalFormula] -> MinimalFormula #

One of the minimal formulas are needed ( min1 | min2 )

mkMinimalAnd :: [MinimalFormula] -> MinimalFormula #

Both of the minimal formulas are needed ( min1 , min2 )

Declaration heads

mkNameDeclHead :: Name -> DeclHead #

Type or class name as a declaration head

mkParenDeclHead :: DeclHead -> DeclHead #

Parenthesized type as a declaration head

mkDeclHeadApp :: DeclHead -> TyVar -> DeclHead #

Application in a declaration head

mkInfixDeclHead :: TyVar -> Operator -> TyVar -> DeclHead #

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 #

Creates a type class instance declaration ( instance X T [where f = ...] )

mkInstanceRule :: Maybe Context -> InstanceHead -> InstanceRule #

The instance declaration rule, which is, roughly, the part of the instance declaration before the where keyword.

mkInstanceHead :: Name -> InstanceHead #

Type or class name as a part of the instance declaration

mkInfixInstanceHead :: Type -> Operator -> InstanceHead #

Infix application of the type/class name to the left operand as a part of the instance declaration

mkParenInstanceHead :: InstanceHead -> InstanceHead #

Parenthesized instance head as a part of the instance declaration

mkAppInstanceHead :: InstanceHead -> Type -> InstanceHead #

Application to one more type as a part of the instance declaration

mkInstanceBody :: [InstBodyDecl] -> InstBody #

Instance body is the implementation of the class functions ( where a x = 1; b x = 2 )

mkInstanceBind :: ValueBind -> InstBodyDecl #

A normal declaration ( f x = 12 ) in a type class instance

mkInstanceTypeSig :: TypeSignature -> InstBodyDecl #

Type signature in instance definition with InstanceSigs

mkInstanceTypeFamilyDef :: TypeEqn -> InstBodyDecl #

An associated type definition ( type A X = B ) in a type class instance

mkInstanceDataFamilyDef :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> InstBodyDecl #

An associated data type implementation ( data A X = C1 | C2 ) int a type class instance

mkInstanceDataFamilyGADTDef :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> [Deriving] -> InstBodyDecl #

An associated data type implemented using GADT style int a type class instance

mkInstanceSpecializePragma :: Type -> InstBodyDecl #

Specialize instance pragma (no phase selection is allowed) in a type class instance

mkEnableOverlap :: OverlapPragma #

OVERLAP pragma for type instance definitions

mkDisableOverlap :: OverlapPragma #

NO_OVERLAP pragma for type instance definitions

mkOverlappable :: OverlapPragma #

OVERLAPPABLE pragma for type instance definitions

mkOverlapping :: OverlapPragma #

OVERLAPPING pragma for type instance definitions

mkOverlaps :: OverlapPragma #

OVERLAPS pragma for type instance definitions

mkIncoherentOverlap :: OverlapPragma #

INCOHERENT pragma for type instance definitions

Type roles

mkRoleDecl :: QualifiedName -> [Role] -> Decl #

Creates a role annotations ( type role Ptr representational )

mkNominalRole :: Role #

Marks a given type parameter as nominal.

mkRepresentationalRole :: Role #

Marks a given type parameter as representational.

mkPhantomRole :: Role #

Marks a given type parameter as phantom.

Foreign imports and exports

mkForeignImport :: CallConv -> Maybe Safety -> Name -> Type -> Decl #

Creates a foreign import ( foreign import foo :: Int -> IO Int )

mkForeignExport :: CallConv -> Name -> Type -> Decl #

Creates a foreign export ( foreign export ccall foo :: Int -> IO Int )

mkStdCall :: CallConv #

Specifies stdcall calling convention for foreign import/export.

mkCCall :: CallConv #

Specifies ccall calling convention for foreign import/export.

mkCApi :: CallConv #

Specifies capi calling convention for foreign import/export.

mkUnsafe :: Safety #

Specifies that the given foreign import is unsafe.

Type and data families

mkTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> Decl #

Creates a type family declaration ( type family F x )

mkClosedTypeFamily :: DeclHead -> Maybe TypeFamilySpec -> [TypeEqn] -> Decl #

Creates a closed type family declaration ( type family F x where F Int = (); F a = Int )

mkDataFamily :: DeclHead -> Maybe KindConstraint -> Decl #

Creates a data family declaration ( data family A a :: * -> * )

mkTypeFamilyKindSpec :: KindConstraint -> TypeFamilySpec #

Specifies the kind of a type family ( :: * -> * )

mkTypeFamilyInjectivitySpec :: TyVar -> [Name] -> TypeFamilySpec #

Specifies the injectivity of a type family ( = r | r -> a )

mkTypeEqn :: Type -> Type -> TypeEqn #

Type equations as found in closed type families ( T A = S )

mkTypeInstance :: InstanceRule -> Type -> Decl #

Creates a type family instance declaration ( type instance Fam T = AssignedT )

mkDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> [ConDecl] -> [Deriving] -> Decl #

Creates a data instance declaration ( data instance Fam T = Con1 | Con2 )

mkGadtDataInstance :: DataOrNewtypeKeyword -> InstanceRule -> Maybe KindConstraint -> [GadtConDecl] -> Decl #

Creates a GADT-style data instance declaration ( data instance Fam T where ... )

Pattern synonyms

mkPatternSynonym :: PatSynLhs -> PatSynRhs -> Decl #

Creates a pattern synonym ( pattern Arrow t1 t2 = App "->" [t1, t2] )

mkConPatSyn :: Name -> [Name] -> PatSynLhs #

Creates a left hand side of a pattern synonym with a constructor name and arguments ( Arrow t1 t2 )

mkInfixPatSyn :: Name -> Operator -> Name -> PatSynLhs #

Creates an infix pattern synonym left-hand side ( t1 :+: t2 )

mkRecordPatSyn :: Name -> [Name] -> PatSynLhs #

Creates a record-style pattern synonym left-hand side ( Arrow { arrowFrom, arrowTo } )

mkSymmetricPatSyn :: Pattern -> PatSynRhs #

Creates an automatically two-way pattern synonym ( = App "Int" [] )

mkOneWayPatSyn :: Pattern -> PatSynRhs #

Creates a pattern synonym that can be only used for pattenr matching but not for combining ( <- App "Int" [] )

mkTwoWayPatSyn :: Pattern -> [Match] -> PatSynRhs #

Creates a pattern synonym with the other direction explicitly specified ( <- App "Int" [] where Int = App "Int" [] )

mkPatternSignatureDecl :: PatternSignature -> Decl #

Creates a pattern type signature declaration ( pattern Succ :: Int -> Int )

Top level pragmas

mkPragmaDecl :: TopLevelPragma -> Decl #

Creates a top-level pragmas

mkRulePragma :: [Rule] -> TopLevelPragma #

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 #

A pragma that marks definitions as deprecated ( {-# DEPRECATED f "f will be replaced by g" #-} )

mkWarningPragma :: [Name] -> String -> TopLevelPragma #

A pragma that marks definitions as deprecated ( {-# WARNING unsafePerformIO "you should know what you are doing" #-} )

mkAnnPragma :: AnnotationSubject -> Expr -> TopLevelPragma #

A pragma that annotates a definition with an arbitrary value ( {-# ANN f 42 #-} )

mkInlinePragma :: Maybe ConlikeAnnot -> Maybe PhaseControl -> Name -> TopLevelPragma #

A pragma that marks a function for inlining to the compiler ( {-# INLINE thenUs #-} )

mkNoInlinePragma :: Name -> TopLevelPragma #

A pragma that forbids a function from being inlined by the compiler ( {-# NOINLINE f #-} )

mkInlinablePragma :: Maybe PhaseControl -> Name -> TopLevelPragma #

A pragma that marks a function that it may be inlined by the compiler ( {-# INLINABLE thenUs #-} )

mkLinePragma :: Int -> Maybe StringNode -> TopLevelPragma #

A pragma for maintaining line numbers in generated sources ( {-# LINE 123 "somefile" #-} )

mkSpecializePragma :: Maybe PhaseControl -> Name -> [Type] -> TopLevelPragma #

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 #

Marks that the pragma should be applied from a given compile phase ( [2] )

mkPhaseControlUntil :: Integer -> PhaseControl #

Marks that the pragma should be applied until a given compile phase ( [~2] )

mkRewriteRule :: String -> Maybe PhaseControl -> [RuleVar] -> Expr -> Expr -> Rule #

A rewrite rule ( "map/map" forall f g xs. map f (map g xs) = map (f.g) xs )

mkNameAnnotation :: Name -> AnnotationSubject #

The definition with the given name is annotated

mkTypeAnnotation :: Name -> AnnotationSubject #

A type with the given name is annotated

mkModuleAnnotation :: AnnotationSubject #

The whole module is annotated

mkConlikeAnnotation :: ConlikeAnnot #

A CONLIKE modifier for an INLINE pragma.