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

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.Tools.AST.Gen.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 dom -> Type dom -> Decl dom Source #

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

mkStandaloneDeriving :: Maybe (OverlapPragma dom) -> InstanceRule dom -> Decl dom Source #

Creates a standalone deriving declaration ( deriving instance X T )

mkFixityDecl :: FixitySignature dom -> Decl dom Source #

Creates a fixity declaration ( infixl 5 +, - )

mkDefaultDecl :: [Type dom] -> Decl dom Source #

Creates default types ( default (T1, T2) )

mkTypeSigDecl :: TypeSignature dom -> Decl dom Source #

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

mkValueBinding :: ValueBind dom -> Decl dom Source #

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

mkSpliceDecl :: Splice dom -> Decl dom Source #

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

Data type definitions

mkDataDecl :: DataOrNewtypeKeyword dom -> Maybe (Context dom) -> DeclHead dom -> [ConDecl dom] -> Maybe (Deriving dom) -> Decl dom Source #

Creates a data or newtype declaration.

mkGADTDataDecl :: DataOrNewtypeKeyword dom -> Maybe (Context dom) -> DeclHead dom -> Maybe (KindConstraint dom) -> [GadtConDecl dom] -> Maybe (Deriving dom) -> Decl dom Source #

Creates a GADT-style data or newtype declaration.

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

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

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

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

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

Creates an ordinary data constructor ( C t1 t2 )

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

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

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

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

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

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

mkDeriving :: [InstanceHead dom] -> Deriving dom Source #

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

mkDataKeyword :: DataOrNewtypeKeyword dom Source #

The data keyword in a type definition

mkNewtypeKeyword :: DataOrNewtypeKeyword dom Source #

The newtype keyword in a type definition

Class declarations

mkClassDecl :: Maybe (Context dom) -> DeclHead dom -> [FunDep dom] -> Maybe (ClassBody dom) -> Decl dom Source #

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

mkClassBody :: [ClassElement dom] -> ClassBody dom Source #

Creates the list of declarations that can appear in a typeclass

mkClassElemSig :: TypeSignature dom -> ClassElement dom Source #

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

mkClassElemDef :: ValueBind dom -> ClassElement dom Source #

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

mkClassElemTypeFam :: DeclHead dom -> Maybe (TypeFamilySpec dom) -> ClassElement dom Source #

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

mkClassElemDataFam :: DeclHead dom -> Maybe (KindConstraint dom) -> ClassElement dom Source #

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

mkClsDefaultType :: DeclHead dom -> Type dom -> ClassElement dom Source #

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

mkClsDefaultSig :: Name dom -> Type dom -> ClassElement dom Source #

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

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

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

mkClsMinimal :: MinimalFormula dom -> ClassElement dom Source #

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

mkMinimalOr :: [MinimalFormula dom] -> MinimalFormula dom Source #

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

mkMinimalAnd :: [MinimalFormula dom] -> MinimalFormula dom Source #

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

Declaration heads

mkNameDeclHead :: Name dom -> DeclHead dom Source #

Type or class name as a declaration head

mkParenDeclHead :: DeclHead dom -> DeclHead dom Source #

Parenthesized type as a declaration head

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

Application in a declaration head

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

Infix application of the type/class name to the left operand in a declaration head

Type class instance declarations

mkInstanceDecl :: Maybe (OverlapPragma dom) -> InstanceRule dom -> Maybe (InstBody dom) -> Decl dom Source #

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

mkInstanceRule :: Maybe (Context dom) -> InstanceHead dom -> InstanceRule dom Source #

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

mkInstanceHead :: Name dom -> InstanceHead dom Source #

Type or class name as a part of the instance declaration

mkInfixInstanceHead :: Type dom -> Operator dom -> InstanceHead dom Source #

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

mkParenInstanceHead :: InstanceHead dom -> InstanceHead dom Source #

Parenthesized instance head as a part of the instance declaration

mkAppInstanceHead :: InstanceHead dom -> Type dom -> InstanceHead dom Source #

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

mkInstanceBody :: [InstBodyDecl dom] -> InstBody dom Source #

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

mkInstanceBind :: ValueBind dom -> InstBodyDecl dom Source #

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

mkInstanceTypeSig :: TypeSignature dom -> InstBodyDecl dom Source #

Type signature in instance definition with InstanceSigs

mkInstanceTypeFamilyDef :: TypeEqn dom -> InstBodyDecl dom Source #

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

mkInstanceDataFamilyDef :: DataOrNewtypeKeyword dom -> InstanceRule dom -> [ConDecl dom] -> Maybe (Deriving dom) -> InstBodyDecl dom Source #

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

mkInstanceDataFamilyGADTDef :: DataOrNewtypeKeyword dom -> InstanceRule dom -> Maybe (KindConstraint dom) -> [GadtConDecl dom] -> Maybe (Deriving dom) -> InstBodyDecl dom Source #

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

mkInstanceSpecializePragma :: Type dom -> InstBodyDecl dom Source #

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

mkEnableOverlap :: OverlapPragma dom Source #

OVERLAP pragma for type instance definitions

mkDisableOverlap :: OverlapPragma dom Source #

NO_OVERLAP pragma for type instance definitions

mkOverlappable :: OverlapPragma dom Source #

OVERLAPPABLE pragma for type instance definitions

mkOverlapping :: OverlapPragma dom Source #

OVERLAPPING pragma for type instance definitions

mkOverlaps :: OverlapPragma dom Source #

OVERLAPS pragma for type instance definitions

mkIncoherentOverlap :: OverlapPragma dom Source #

INCOHERENT pragma for type instance definitions

Type roles

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

Creates a role annotations ( type role Ptr representational )

mkNominalRole :: Role dom Source #

Marks a given type parameter as nominal.

mkRepresentationalRole :: Role dom Source #

Marks a given type parameter as representational.

mkPhantomRole :: Role dom Source #

Marks a given type parameter as phantom.

Foreign imports and exports

mkForeignImport :: CallConv dom -> Maybe (Safety dom) -> Name dom -> Type dom -> Decl dom Source #

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

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

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

mkStdCall :: CallConv dom Source #

Specifies stdcall calling convention for foreign import/export.

mkCCall :: CallConv dom Source #

Specifies ccall calling convention for foreign import/export.

mkCApi :: CallConv dom Source #

Specifies capi calling convention for foreign import/export.

mkUnsafe :: Safety dom Source #

Specifies that the given foreign import is unsafe.

Type and data families

mkTypeFamily :: DeclHead dom -> Maybe (TypeFamilySpec dom) -> Decl dom Source #

Creates a type family declaration ( type family F x )

mkClosedTypeFamily :: DeclHead dom -> Maybe (TypeFamilySpec dom) -> [TypeEqn dom] -> Decl dom Source #

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

mkDataFamily :: DeclHead dom -> Maybe (KindConstraint dom) -> Decl dom Source #

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

mkTypeFamilyKindSpec :: KindConstraint dom -> TypeFamilySpec dom Source #

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

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

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

mkTypeEqn :: Type dom -> Type dom -> TypeEqn dom Source #

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

mkTypeInstance :: InstanceRule dom -> Type dom -> Decl dom Source #

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

mkDataInstance :: DataOrNewtypeKeyword dom -> InstanceRule dom -> [ConDecl dom] -> Maybe (Deriving dom) -> Decl dom Source #

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

mkGadtDataInstance :: DataOrNewtypeKeyword dom -> InstanceRule dom -> Maybe (KindConstraint dom) -> [GadtConDecl dom] -> Decl dom Source #

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

Pattern synonyms

mkPatternSynonym :: PatSynLhs dom -> PatSynRhs dom -> Decl dom Source #

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

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

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

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

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

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

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

mkSymmetricPatSyn :: Pattern dom -> PatSynRhs dom Source #

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

mkOneWayPatSyn :: Pattern dom -> PatSynRhs dom Source #

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

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

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

mkPatternSignatureDecl :: PatternSignature dom -> Decl dom Source #

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

Top level pragmas

mkPragmaDecl :: TopLevelPragma dom -> Decl dom Source #

Creates a top-level pragmas

mkRulePragma :: [Rule dom] -> TopLevelPragma dom 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 dom] -> String -> TopLevelPragma dom Source #

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

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

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

mkAnnPragma :: AnnotationSubject dom -> Expr dom -> TopLevelPragma dom Source #

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

mkInlinePragma :: Maybe (ConlikeAnnot dom) -> Maybe (PhaseControl dom) -> Name dom -> TopLevelPragma dom Source #

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

mkNoInlinePragma :: Name dom -> TopLevelPragma dom Source #

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

mkInlinablePragma :: Maybe (PhaseControl dom) -> Name dom -> TopLevelPragma dom Source #

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

mkLinePragma :: Int -> Maybe (StringNode dom) -> TopLevelPragma dom Source #

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

mkSpecializePragma :: Maybe (PhaseControl dom) -> Name dom -> [Type dom] -> TopLevelPragma dom 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 dom Source #

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

mkPhaseControlUntil :: Integer -> PhaseControl dom Source #

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

mkRewriteRule :: String -> Maybe (PhaseControl dom) -> [RuleVar dom] -> Expr dom -> Expr dom -> Rule dom Source #

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

mkRuleVar :: Name dom -> RuleVar dom Source #

mkNameAnnotation :: Name dom -> AnnotationSubject dom Source #

The definition with the given name is annotated

mkTypeAnnotation :: Name dom -> AnnotationSubject dom Source #

A type with the given name is annotated

mkModuleAnnotation :: AnnotationSubject dom Source #

The whole module is annotated

mkConlikeAnnotation :: ConlikeAnnot dom Source #

A CONLIKE modifier for an INLINE pragma.