lens-4.13: Lenses, Folds and Traversals

Copyright | (C) 2012-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | TemplateHaskell
Safe Haskell | Trustworthy
Language | Haskell98

Language.Haskell.TH.Lens

Contents

- Traversals
- Lenses
  - Loc Lenses
  - FunDep Lenses
  - Match Lenses
  - Fixity Lenses
  - Clause Lenses
  - FieldExp Lenses
  - FieldPat Lenses
  - TySynEqn Lenses
- Prisms
  - Info Prisms
  - Dec Prisms
  - Con Prisms
  - Strict Prisms
  - Foreign Prisms
  - Callconv Prisms
  - Safety Prisms
  - Pragma Prisms
  - Inline Prisms
  - RuleMatch Prisms
  - Phases Prisms
  - RuleBndr Prisms
  - AnnTarget Prisms
  - FunDep Prisms TODO make a lens
  - FamFlavour Prisms
  - FixityDirection Prisms
  - Exp Prisms
  - Body Prisms
  - Guard Prisms
  - Stmt Prisms
  - Range Prisms
  - Lit Prisms
  - Pat Prisms
  - Type Prisms
  - TyVarBndr Prisms
  - TyLit Prisms
  - Role Prisms

Description

Lenses, Prisms, and Traversals for working with Template Haskell

Synopsis

- class HasName t where
  - name :: Lens' t Name
- class HasTypes t where
  - types :: Traversal' t Type
- class HasTypeVars t where
  - typeVarsEx :: Set Name -> Traversal' t Name
- class SubstType t where
  - substType :: Map Name Type -> t -> t
- typeVars :: HasTypeVars t => Traversal' t Name
- substTypeVars :: HasTypeVars t => Map Name Name -> t -> t
- conFields :: Traversal' Con StrictType
- conNamedFields :: Traversal' Con VarStrictType
- locFileName :: Lens' Loc String
- locPackage :: Lens' Loc String
- locModule :: Lens' Loc String
- locStart :: Lens' Loc CharPos
- locEnd :: Lens' Loc CharPos
- funDepInputs :: Lens' FunDep [Name]
- funDepOutputs :: Lens' FunDep [Name]
- matchPattern :: Lens' Match Pat
- matchBody :: Lens' Match Body
- matchDeclarations :: Lens' Match [Dec]
- fixityPrecedence :: Lens' Fixity Int
- fixityDirection :: Lens' Fixity FixityDirection
- clausePattern :: Lens' Clause [Pat]
- clauseBody :: Lens' Clause Body
- clauseDecs :: Lens' Clause [Dec]
- fieldExpName :: Lens' FieldExp Name
- fieldExpExpression :: Lens' FieldExp Exp
- fieldPatName :: Lens' FieldPat Name
- fieldPatPattern :: Lens' FieldPat Pat
- tySynEqnPatterns :: Lens' TySynEqn [Type]
- tySynEqnResult :: Lens' TySynEqn Type
- _ClassI :: Prism' Info (Dec, [InstanceDec])
- _ClassOpI :: Prism' Info (Name, Type, ParentName, Fixity)
- _TyConI :: Prism' Info Dec
- _FamilyI :: Prism' Info (Dec, [InstanceDec])
- _PrimTyConI :: Prism' Info (Name, Arity, Unlifted)
- _DataConI :: Prism' Info (Name, Type, ParentName, Fixity)
- _VarI :: Prism' Info (Name, Type, Maybe Dec, Fixity)
- _TyVarI :: Prism' Info (Name, Type)
- _FunD :: Prism' Dec (Name, [Clause])
- _ValD :: Prism' Dec (Pat, Body, [Dec])
- _DataD :: Prism' Dec (Cxt, Name, [TyVarBndr], [Con], [Name])
- _NewtypeD :: Prism' Dec (Cxt, Name, [TyVarBndr], Con, [Name])
- _TySynD :: Prism' Dec (Name, [TyVarBndr], Type)
- _ClassD :: Prism' Dec (Cxt, Name, [TyVarBndr], [FunDep], [Dec])
- _InstanceD :: Prism' Dec (Cxt, Type, [Dec])
- _SigD :: Prism' Dec (Name, Type)
- _ForeignD :: Prism' Dec Foreign
- _InfixD :: Prism' Dec (Fixity, Name)
- _PragmaD :: Prism' Dec Pragma
- _FamilyD :: Prism' Dec (FamFlavour, Name, [TyVarBndr], Maybe Kind)
- _DataInstD :: Prism' Dec (Cxt, Name, [Type], [Con], [Name])
- _NewtypeInstD :: Prism' Dec (Cxt, Name, [Type], Con, [Name])
- _TySynInstD :: Prism' Dec (Name, TySynEqn)
- _ClosedTypeFamilyD :: Prism' Dec (Name, [TyVarBndr], Maybe Kind, [TySynEqn])
- _RoleAnnotD :: Prism' Dec (Name, [Role])
- _StandaloneDerivD :: Prism' Dec (Cxt, Type)
- _DefaultSigD :: Prism' Dec (Name, Type)
- _NormalC :: Prism' Con (Name, [StrictType])
- _RecC :: Prism' Con (Name, [VarStrictType])
- _InfixC :: Prism' Con (StrictType, Name, StrictType)
- _ForallC :: Prism' Con ([TyVarBndr], Cxt, Con)
- _IsStrict :: Prism' Strict ()
- _NotStrict :: Prism' Strict ()
- _Unpacked :: Prism' Strict ()
- _ImportF :: Prism' Foreign (Callconv, Safety, String, Name, Type)
- _ExportF :: Prism' Foreign (Callconv, String, Name, Type)
- _CCall :: Prism' Callconv ()
- _StdCall :: Prism' Callconv ()
- _CApi :: Prism' Callconv ()
- _Prim :: Prism' Callconv ()
- _JavaScript :: Prism' Callconv ()
- _Unsafe :: Prism' Safety ()
- _Safe :: Prism' Safety ()
- _Interruptible :: Prism' Safety ()
- _InlineP :: Prism' Pragma (Name, Inline, RuleMatch, Phases)
- _SpecialiseP :: Prism' Pragma (Name, Type, Maybe Inline, Phases)
- _SpecialiseInstP :: Prism' Pragma Type
- _RuleP :: Prism' Pragma (String, [RuleBndr], Exp, Exp, Phases)
- _AnnP :: Prism' Pragma (AnnTarget, Exp)
- _LineP :: Prism' Pragma (Int, String)
- _NoInline :: Prism' Inline ()
- _Inline :: Prism' Inline ()
- _Inlinable :: Prism' Inline ()
- _ConLike :: Prism' RuleMatch ()
- _FunLike :: Prism' RuleMatch ()
- _AllPhases :: Prism' Phases ()
- _FromPhase :: Prism' Phases Int
- _BeforePhase :: Prism' Phases Int
- _RuleVar :: Prism' RuleBndr Name
- _TypedRuleVar :: Prism' RuleBndr (Name, Type)
- _ModuleAnnotation :: Prism' AnnTarget ()
- _TypeAnnotation :: Prism' AnnTarget Name
- _ValueAnnotation :: Prism' AnnTarget Name
- _FunDep :: Iso' FunDep ([Name], [Name])
- _TypeFam :: Prism' FamFlavour ()
- _DataFam :: Prism' FamFlavour ()
- _InfixL :: Prism' FixityDirection ()
- _InfixR :: Prism' FixityDirection ()
- _InfixN :: Prism' FixityDirection ()
- _VarE :: Prism' Exp Name
- _ConE :: Prism' Exp Name
- _LitE :: Prism' Exp Lit
- _AppE :: Prism' Exp (Exp, Exp)
- _InfixE :: Prism' Exp (Maybe Exp, Exp, Maybe Exp)
- _UInfixE :: Prism' Exp (Exp, Exp, Exp)
- _ParensE :: Prism' Exp Exp
- _LamE :: Prism' Exp ([Pat], Exp)
- _LamCaseE :: Prism' Exp [Match]
- _TupE :: Prism' Exp [Exp]
- _UnboxedTupE :: Prism' Exp [Exp]
- _CondE :: Prism' Exp (Exp, Exp, Exp)
- _MultiIfE :: Prism' Exp [(Guard, Exp)]
- _LetE :: Prism' Exp ([Dec], Exp)
- _CaseE :: Prism' Exp (Exp, [Match])
- _DoE :: Prism' Exp [Stmt]
- _CompE :: Prism' Exp [Stmt]
- _ArithSeqE :: Prism' Exp Range
- _ListE :: Prism' Exp [Exp]
- _SigE :: Prism' Exp (Exp, Type)
- _RecConE :: Prism' Exp (Name, [FieldExp])
- _RecUpdE :: Prism' Exp (Exp, [FieldExp])
- _StaticE :: Prism' Exp Exp
- _GuardedB :: Prism' Body [(Guard, Exp)]
- _NormalB :: Prism' Body Exp
- _NormalG :: Prism' Guard Exp
- _PatG :: Prism' Guard [Stmt]
- _BindS :: Prism' Stmt (Pat, Exp)
- _LetS :: Prism' Stmt [Dec]
- _NoBindS :: Prism' Stmt Exp
- _ParS :: Prism' Stmt [[Stmt]]
- _FromR :: Prism' Range Exp
- _FromThenR :: Prism' Range (Exp, Exp)
- _FromToR :: Prism' Range (Exp, Exp)
- _FromThenToR :: Prism' Range (Exp, Exp, Exp)
- _CharL :: Prism' Lit Char
- _StringL :: Prism' Lit String
- _IntegerL :: Prism' Lit Integer
- _RationalL :: Prism' Lit Rational
- _IntPrimL :: Prism' Lit Integer
- _WordPrimL :: Prism' Lit Integer
- _FloatPrimL :: Prism' Lit Rational
- _DoublePrimL :: Prism' Lit Rational
- _StringPrimL :: Prism' Lit [Word8]
- _LitP :: Prism' Pat Lit
- _VarP :: Prism' Pat Name
- _TupP :: Prism' Pat [Pat]
- _UnboxedTupP :: Prism' Pat [Pat]
- _ConP :: Prism' Pat (Name, [Pat])
- _InfixP :: Prism' Pat (Pat, Name, Pat)
- _UInfixP :: Prism' Pat (Pat, Name, Pat)
- _ParensP :: Prism' Pat Pat
- _TildeP :: Prism' Pat Pat
- _BangP :: Prism' Pat Pat
- _AsP :: Prism' Pat (Name, Pat)
- _WildP :: Prism' Pat ()
- _RecP :: Prism' Pat (Name, [FieldPat])
- _ListP :: Prism' Pat [Pat]
- _SigP :: Prism' Pat (Pat, Type)
- _ViewP :: Prism' Pat (Exp, Pat)
- _ForallT :: Prism' Type ([TyVarBndr], Cxt, Type)
- _AppT :: Prism' Type (Type, Type)
- _SigT :: Prism' Type (Type, Kind)
- _VarT :: Prism' Type Name
- _ConT :: Prism' Type Name
- _PromotedT :: Prism' Type Name
- _TupleT :: Prism' Type Int
- _UnboxedTupleT :: Prism' Type Int
- _ArrowT :: Prism' Type ()
- _EqualityT :: Prism' Type ()
- _ListT :: Prism' Type ()
- _PromotedTupleT :: Prism' Type Int
- _PromotedNilT :: Prism' Type ()
- _PromotedConsT :: Prism' Type ()
- _StarT :: Prism' Type ()
- _ConstraintT :: Prism' Type ()
- _LitT :: Prism' Type TyLit
- _PlainTV :: Prism' TyVarBndr Name
- _KindedTV :: Prism' TyVarBndr (Name, Kind)
- _NumTyLit :: Prism' TyLit Integer
- _StrTyLit :: Prism' TyLit String
- _NominalR :: Prism' Role ()
- _RepresentationalR :: Prism' Role ()
- _PhantomR :: Prism' Role ()
- _InferR :: Prism' Role ()

# Traversals

class HasName t where Source

Has a `Name`

Methods

name :: Lens' t Name Source

Extract (or modify) the `Name` of something

Instances

HasName Name Source |
HasName TyVarBndr Source |
HasName Con Source |

class HasTypes t where Source

Contains some amount of `Type`s inside

Methods

types :: Traversal' t Type Source

Traverse all the types

Instances

HasTypes Type Source |
HasTypes Con Source |
HasTypes t => HasTypes [t] Source |

class HasTypeVars t where Source

Provides for the extraction of free type variables, and alpha renaming.

Methods

typeVarsEx :: Set Name -> Traversal' t Name Source

When performing substitution into this traversal you're not allowed to substitute in a name that is bound internally or you'll violate the `Traversal` laws, when in doubt generate your names with `newName`.

Instances

HasTypeVars Type Source |
HasTypeVars Name Source |
HasTypeVars TyVarBndr Source |
HasTypeVars Con Source |
HasTypeVars t => HasTypeVars [t] Source |
HasTypeVars t => HasTypeVars (Maybe t) Source |

class SubstType t where Source

Provides substitution for types

Methods

substType :: Map Name Type -> t -> t Source

Perform substitution for types

Instances

SubstType Type Source |
SubstType t => SubstType [t] Source |

typeVars :: HasTypeVars t => Traversal' t Name Source

Traverse free type variables

substTypeVars :: HasTypeVars t => Map Name Name -> t -> t Source

Substitute using a map of names in for free type variables

conFields :: Traversal' Con StrictType Source

Provides a `Traversal` of the types of each field of a constructor.

conNamedFields :: Traversal' Con VarStrictType Source

`Traversal` of the types of the named fields of a constructor.

# Lenses

## Loc Lenses

locFileName :: Lens' Loc String Source

locPackage :: Lens' Loc String Source

locModule :: Lens' Loc String Source

locStart :: Lens' Loc CharPos Source

locEnd :: Lens' Loc CharPos Source

## FunDep Lenses

funDepInputs :: Lens' FunDep [Name] Source

funDepOutputs :: Lens' FunDep [Name] Source

## Match Lenses

matchPattern :: Lens' Match Pat Source

matchBody :: Lens' Match Body Source

matchDeclarations :: Lens' Match [Dec] Source

## Fixity Lenses

fixityPrecedence :: Lens' Fixity Int Source

fixityDirection :: Lens' Fixity FixityDirection Source

## Clause Lenses

clausePattern :: Lens' Clause [Pat] Source

clauseBody :: Lens' Clause Body Source

clauseDecs :: Lens' Clause [Dec] Source

## FieldExp Lenses

fieldExpName :: Lens' FieldExp Name Source

fieldExpExpression :: Lens' FieldExp Exp Source

## FieldPat Lenses

fieldPatName :: Lens' FieldPat Name Source

fieldPatPattern :: Lens' FieldPat Pat Source

## TySynEqn Lenses

tySynEqnPatterns :: Lens' TySynEqn [Type] Source

tySynEqnResult :: Lens' TySynEqn Type Source

# Prisms

## Info Prisms

_ClassI :: Prism' Info (Dec, [InstanceDec]) Source

_ClassOpI :: Prism' Info (Name, Type, ParentName, Fixity) Source

_TyConI :: Prism' Info Dec Source

_FamilyI :: Prism' Info (Dec, [InstanceDec]) Source

_PrimTyConI :: Prism' Info (Name, Arity, Unlifted) Source

_DataConI :: Prism' Info (Name, Type, ParentName, Fixity) Source

_VarI :: Prism' Info (Name, Type, Maybe Dec, Fixity) Source

_TyVarI :: Prism' Info (Name, Type) Source

## Dec Prisms

_FunD :: Prism' Dec (Name, [Clause]) Source

_ValD :: Prism' Dec (Pat, Body, [Dec]) Source

_DataD :: Prism' Dec (Cxt, Name, [TyVarBndr], [Con], [Name]) Source

_NewtypeD :: Prism' Dec (Cxt, Name, [TyVarBndr], Con, [Name]) Source

_TySynD :: Prism' Dec (Name, [TyVarBndr], Type) Source

_ClassD :: Prism' Dec (Cxt, Name, [TyVarBndr], [FunDep], [Dec]) Source

_InstanceD :: Prism' Dec (Cxt, Type, [Dec]) Source

_SigD :: Prism' Dec (Name, Type) Source

_ForeignD :: Prism' Dec Foreign Source

_InfixD :: Prism' Dec (Fixity, Name) Source

_PragmaD :: Prism' Dec Pragma Source

_FamilyD :: Prism' Dec (FamFlavour, Name, [TyVarBndr], Maybe Kind) Source

_DataInstD :: Prism' Dec (Cxt, Name, [Type], [Con], [Name]) Source

_NewtypeInstD :: Prism' Dec (Cxt, Name, [Type], Con, [Name]) Source

_TySynInstD :: Prism' Dec (Name, TySynEqn) Source

_ClosedTypeFamilyD :: Prism' Dec (Name, [TyVarBndr], Maybe Kind, [TySynEqn]) Source

_RoleAnnotD :: Prism' Dec (Name, [Role]) Source

_StandaloneDerivD :: Prism' Dec (Cxt, Type) Source

_DefaultSigD :: Prism' Dec (Name, Type) Source

## Con Prisms

_NormalC :: Prism' Con (Name, [StrictType]) Source

_RecC :: Prism' Con (Name, [VarStrictType]) Source

_InfixC :: Prism' Con (StrictType, Name, StrictType) Source

_ForallC :: Prism' Con ([TyVarBndr], Cxt, Con) Source

## Strict Prisms

_IsStrict :: Prism' Strict () Source

_NotStrict :: Prism' Strict () Source

_Unpacked :: Prism' Strict () Source

## Foreign Prisms

_ImportF :: Prism' Foreign (Callconv, Safety, String, Name, Type) Source

_ExportF :: Prism' Foreign (Callconv, String, Name, Type) Source

## Callconv Prisms

_CCall :: Prism' Callconv () Source

_StdCall :: Prism' Callconv () Source

_CApi :: Prism' Callconv () Source

_Prim :: Prism' Callconv () Source

_JavaScript :: Prism' Callconv () Source

## Safety Prisms

_Unsafe :: Prism' Safety () Source

_Safe :: Prism' Safety () Source

_Interruptible :: Prism' Safety () Source

## Pragma Prisms

_InlineP :: Prism' Pragma (Name, Inline, RuleMatch, Phases) Source

_SpecialiseP :: Prism' Pragma (Name, Type, Maybe Inline, Phases) Source

_SpecialiseInstP :: Prism' Pragma Type Source

_RuleP :: Prism' Pragma (String, [RuleBndr], Exp, Exp, Phases) Source

_AnnP :: Prism' Pragma (AnnTarget, Exp) Source

_LineP :: Prism' Pragma (Int, String) Source

## Inline Prisms

_NoInline :: Prism' Inline () Source

_Inline :: Prism' Inline () Source

_Inlinable :: Prism' Inline () Source

## RuleMatch Prisms

_ConLike :: Prism' RuleMatch () Source

_FunLike :: Prism' RuleMatch () Source

## Phases Prisms

_AllPhases :: Prism' Phases () Source

_FromPhase :: Prism' Phases Int Source

_BeforePhase :: Prism' Phases Int Source

## RuleBndr Prisms

_RuleVar :: Prism' RuleBndr Name Source

_TypedRuleVar :: Prism' RuleBndr (Name, Type) Source

## AnnTarget Prisms

_ModuleAnnotation :: Prism' AnnTarget () Source

_TypeAnnotation :: Prism' AnnTarget Name Source

_ValueAnnotation :: Prism' AnnTarget Name Source

## FunDep Prisms TODO make a lens

_FunDep :: Iso' FunDep ([Name], [Name]) Source

## FamFlavour Prisms

_TypeFam :: Prism' FamFlavour () Source

_DataFam :: Prism' FamFlavour () Source

## FixityDirection Prisms

_InfixL :: Prism' FixityDirection () Source

_InfixR :: Prism' FixityDirection () Source

_InfixN :: Prism' FixityDirection () Source

## Exp Prisms

_VarE :: Prism' Exp Name Source

_ConE :: Prism' Exp Name Source

_LitE :: Prism' Exp Lit Source

_AppE :: Prism' Exp (Exp, Exp) Source

_InfixE :: Prism' Exp (Maybe Exp, Exp, Maybe Exp) Source

_UInfixE :: Prism' Exp (Exp, Exp, Exp) Source

_ParensE :: Prism' Exp Exp Source

_LamE :: Prism' Exp ([Pat], Exp) Source

_LamCaseE :: Prism' Exp [Match] Source

_TupE :: Prism' Exp [Exp] Source

_UnboxedTupE :: Prism' Exp [Exp] Source

_CondE :: Prism' Exp (Exp, Exp, Exp) Source

_MultiIfE :: Prism' Exp [(Guard, Exp)] Source

_LetE :: Prism' Exp ([Dec], Exp) Source

_CaseE :: Prism' Exp (Exp, [Match]) Source

_DoE :: Prism' Exp [Stmt] Source

_CompE :: Prism' Exp [Stmt] Source

_ArithSeqE :: Prism' Exp Range Source

_ListE :: Prism' Exp [Exp] Source

_SigE :: Prism' Exp (Exp, Type) Source

_RecConE :: Prism' Exp (Name, [FieldExp]) Source

_RecUpdE :: Prism' Exp (Exp, [FieldExp]) Source

_StaticE :: Prism' Exp Exp Source

## Body Prisms

_GuardedB :: Prism' Body [(Guard, Exp)] Source

_NormalB :: Prism' Body Exp Source

## Guard Prisms

_NormalG :: Prism' Guard Exp Source

_PatG :: Prism' Guard [Stmt] Source

## Stmt Prisms

_BindS :: Prism' Stmt (Pat, Exp) Source

_LetS :: Prism' Stmt [Dec] Source

_NoBindS :: Prism' Stmt Exp Source

_ParS :: Prism' Stmt [[Stmt]] Source

## Range Prisms

_FromR :: Prism' Range Exp Source

_FromThenR :: Prism' Range (Exp, Exp) Source

_FromToR :: Prism' Range (Exp, Exp) Source

_FromThenToR :: Prism' Range (Exp, Exp, Exp) Source

## Lit Prisms

_CharL :: Prism' Lit Char Source

_StringL :: Prism' Lit String Source

_IntegerL :: Prism' Lit Integer Source

_RationalL :: Prism' Lit Rational Source

_IntPrimL :: Prism' Lit Integer Source

_WordPrimL :: Prism' Lit Integer Source

_FloatPrimL :: Prism' Lit Rational Source

_DoublePrimL :: Prism' Lit Rational Source

_StringPrimL :: Prism' Lit [Word8] Source

## Pat Prisms

_LitP :: Prism' Pat Lit Source

_VarP :: Prism' Pat Name Source

_TupP :: Prism' Pat [Pat] Source

_UnboxedTupP :: Prism' Pat [Pat] Source

_ConP :: Prism' Pat (Name, [Pat]) Source

_InfixP :: Prism' Pat (Pat, Name, Pat) Source

_UInfixP :: Prism' Pat (Pat, Name, Pat) Source

_ParensP :: Prism' Pat Pat Source

_TildeP :: Prism' Pat Pat Source

_BangP :: Prism' Pat Pat Source

_AsP :: Prism' Pat (Name, Pat) Source

_WildP :: Prism' Pat () Source

_RecP :: Prism' Pat (Name, [FieldPat]) Source

_ListP :: Prism' Pat [Pat] Source

_SigP :: Prism' Pat (Pat, Type) Source

_ViewP :: Prism' Pat (Exp, Pat) Source

## Type Prisms

_ForallT :: Prism' Type ([TyVarBndr], Cxt, Type) Source

_AppT :: Prism' Type (Type, Type) Source

_SigT :: Prism' Type (Type, Kind) Source

_VarT :: Prism' Type Name Source

_ConT :: Prism' Type Name Source

_PromotedT :: Prism' Type Name Source

_TupleT :: Prism' Type Int Source

_UnboxedTupleT :: Prism' Type Int Source

_ArrowT :: Prism' Type () Source

_EqualityT :: Prism' Type () Source

_ListT :: Prism' Type () Source

_PromotedTupleT :: Prism' Type Int Source

_PromotedNilT :: Prism' Type () Source

_PromotedConsT :: Prism' Type () Source

_StarT :: Prism' Type () Source

_ConstraintT :: Prism' Type () Source

_LitT :: Prism' Type TyLit Source

## TyVarBndr Prisms

_PlainTV :: Prism' TyVarBndr Name Source

_KindedTV :: Prism' TyVarBndr (Name, Kind) Source

## TyLit Prisms

_NumTyLit :: Prism' TyLit Integer Source

_StrTyLit :: Prism' TyLit String Source

## Role Prisms

_NominalR :: Prism' Role () Source

_RepresentationalR :: Prism' Role () Source

_PhantomR :: Prism' Role () Source

_InferR :: Prism' Role () Source