-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Graph of the subtype relation -- @package th-typegraph @version 0.17 module Language.Haskell.TH.TypeGraph.Hints -- | When a VertexHint value is associated with a Type it describes -- alterations in the type graph from the usual default. data VertexHint -- | normal case Normal :: VertexHint -- | don't create this vertex, no in or out edges Hidden :: VertexHint -- | out degree zero - don't create any out edges Sink :: VertexHint -- | replace all out edges with an edge to an alternate type Divert :: Type -> VertexHint -- | add an extra out edge to the given type Extra :: Type -> VertexHint class HasVertexHints hint hasVertexHints :: (HasVertexHints hint, DsMonad m) => hint -> m [VertexHint] vertexHintTypes :: VertexHint -> [Type] instance Eq VertexHint instance Ord VertexHint instance Show VertexHint instance HasVertexHints VertexHint instance Ppr VertexHint instance Lift VertexHint instance Default VertexHint -- | The Expanded class helps keep track of which Type values -- have been fully expanded to a canonical form. This lets us use the -- Eq and Ord relationships on Type and Pred -- values when reasoning about instance context. What the -- expandType function does is use the function from -- th-desugar to replace occurrences of ConT name with -- the associated Type if name is a declared type synonym -- TySynD name _ typ. For convenience, a wrapper type E -- is provided, along with the Expanded instances E Type -- and E Pred. Now the expandType and expandPred -- functions can be used to return values of type E Type and -- E Pred respectively. -- -- Instances Expanded Type Type and Expanded Pred Pred -- are provided in Language.Haskell.TH.Context.Unsafe, for when -- less type safety is required. module Language.Haskell.TH.TypeGraph.Expand -- | This class lets us use the same expand* functions to work with -- specially marked expanded types or with the original types. class Expanded un ex | ex -> un markExpanded :: Expanded un ex => un -> ex runExpanded' :: Expanded un ex => ex -> un runExpanded :: Expanded a (E a) => E a -> a -- | Apply the th-desugar expand function to a Type and mark it as -- expanded. expandType :: (DsMonad m, Expanded Type e) => Type -> m e -- | Apply the th-desugar expand function to a Pred and mark it as -- expanded. Note that the definition of Pred changed in -- template-haskell-2.10.0.0. expandPred :: (DsMonad m, Expanded Pred e) => Pred -> m e -- | Expand a list of Type and build an expanded ClassP -- Pred. expandClassP :: (DsMonad m, Expanded Pred e) => Name -> [Type] -> m e -- | A concrete type for which Expanded instances are declared below. newtype E a E :: a -> E a instance Eq a => Eq (E a) instance Ord a => Ord (E a) instance Show a => Show (E a) instance Ppr a => Ppr (E a) instance Expanded Pred (E Pred) instance Expanded Type (E Type) -- | Degenerate instances of Expanded that must be explicitly imported if -- you want to use them. They are fine for simple uses of expandType, but -- not if you are trying to use the return value of expandType as a Map -- key. module Language.Haskell.TH.TypeGraph.Unsafe instance Expanded Pred Pred instance Expanded Type Type -- | Helper functions for dealing with record fields, type shape, type -- arity, primitive types, and pretty printing. module Language.Haskell.TH.TypeGraph.Core unReify :: Data a => a -> a unReifyName :: Name -> Name data FieldType FieldType :: Int -> Either StrictType VarStrictType -> FieldType fPos :: FieldType -> Int fNameAndType :: FieldType -> Either StrictType VarStrictType type Field = (Name, Name, Either Int Name) fName :: FieldType -> Maybe Name -- | fType' with leading foralls stripped fType :: FieldType -> Type constructorFields :: Con -> [FieldType] -- | Given the list of constructors from a Dec, dispatch on the different -- levels of complexity of the type they represent - a wrapper is a -- single arity one constructor, an enum is several arity zero -- constructors, and so on. foldShape :: Monad m => ([(Con, [FieldType])] -> m r) -> (Con -> [FieldType] -> m r) -> ([Con] -> m r) -> (Con -> FieldType -> m r) -> [Con] -> m r constructorName :: Con -> Name -- | Compute the arity of a type - the number of type parameters that must -- be applied to it in order to obtain a concrete type. typeArity :: Quasi m => Type -> m Int -- | Pretty print a Ppr value on a single line with each block of -- white space (newlines, tabs, etc.) converted to a single space. pprint' :: Ppr a => a -> [Char] instance Typeable FieldType instance Eq FieldType instance Ord FieldType instance Show FieldType instance Data FieldType instance Lift (E Type) instance (Lift a, Lift b) => Lift (Map a b) instance Lift a => Lift (Set a) instance Ppr (Maybe Field, Type) instance Ppr (Maybe Field, E Type) instance Ppr FieldType instance Ppr () instance Ppr Field -- | Abstract operations on Maps containing graph edges. module Language.Haskell.TH.TypeGraph.Graph type GraphEdges label key = Map key (label, Set key) -- | Build a graph from the result of typeGraphEdges, each edge goes from a -- type to one of the types it contains. Thus, each edge represents a -- primitive lens, and each path in the graph is a composition of lenses. graphFromMap :: Ord key => GraphEdges label key -> (Graph, Vertex -> (label, key, [key]), key -> Maybe Vertex) -- | Isolate and remove some nodes cut :: (Eq a, Ord a) => Set a -> GraphEdges label a -> GraphEdges label a -- | Monadic predicate version of cut. cutM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges label a -> m (GraphEdges label a) -- | Remove all the in- and out-edges of some nodes isolate :: (Eq a, Ord a) => Set a -> GraphEdges label a -> GraphEdges label a -- | Monadic predicate version of isolate. isolateM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges label a -> m (GraphEdges label a) -- | Remove some nodes and extend each of their in-edges to each of their -- out-edges dissolve :: (Eq a, Ord a) => Set a -> GraphEdges label a -> GraphEdges label a -- | Monadic predicate version of dissolve. dissolveM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges label a -> m (GraphEdges label a) instance Ppr key => Ppr (GraphEdges label key) module Language.Haskell.TH.TypeGraph.Info -- | Information collected about the graph implied by the structure of one -- or more Type values. data TypeGraphInfo hint emptyTypeGraphInfo :: TypeGraphInfo hint -- | Build a TypeGraphInfo value by scanning the supplied types and hints. typeGraphInfo :: (DsMonad m, HasVertexHints hint) => [(Maybe Field, Name, hint)] -> [Type] -> m (TypeGraphInfo hint) fields :: Lens' (TypeGraphInfo hint_an6R) (Map (E Type) (Set (Name, Name, Either Int Name))) hints :: Lens (TypeGraphInfo hint_an6R) (TypeGraphInfo hint_anDv) [(Maybe Field, Name, hint_an6R)] [(Maybe Field, Name, hint_anDv)] infoMap :: Lens' (TypeGraphInfo hint_an6R) (Map Name Info) synonyms :: Lens' (TypeGraphInfo hint_an6R) (Map (E Type) (Set Name)) typeSet :: Lens' (TypeGraphInfo hint_an6R) (Set Type) instance Lift hint => Lift (TypeGraphInfo hint) instance Show hint => Show (TypeGraphInfo hint) instance Eq hint => Eq (TypeGraphInfo hint) instance Ord hint => Ord (TypeGraphInfo hint) instance Ppr hint => Ppr (TypeGraphInfo hint) module Language.Haskell.TH.TypeGraph.Vertex -- | For simple type graphs always set _field and _synonyms to Nothing. data TypeGraphVertex TypeGraphVertex :: Maybe (Name, Name, Either Int Name) -> Set Name -> E Type -> TypeGraphVertex -- | The record filed which contains this type _field :: TypeGraphVertex -> Maybe (Name, Name, Either Int Name) -- | All the type synonyms that expand to this type _syns :: TypeGraphVertex -> Set Name -- | The fully expanded type _etype :: TypeGraphVertex -> E Type field :: Lens' TypeGraphVertex (Maybe (Name, Name, Either Int Name)) syns :: Lens' TypeGraphVertex (Set Name) etype :: Lens' TypeGraphVertex (E Type) -- | Return the set of Name of a type's synonyms, plus the name (if -- any) used in its data declaration. Note that this might return the -- empty set. typeNames :: TypeGraphVertex -> Set Name bestType :: TypeGraphVertex -> Type typeVertex :: DsMonad m => Type -> m TypeGraphVertex fieldVertex :: DsMonad m => Type -> (Name, Name, Either Int Name) -> m TypeGraphVertex oldVertex :: DsMonad m => (Maybe Field, Type) -> m TypeGraphVertex instance Lift TypeGraphVertex instance Eq TypeGraphVertex instance Ord TypeGraphVertex instance Show TypeGraphVertex instance Ppr TypeGraphVertex -- | Operations using MonadReader (TypeGraphInfo hint). module Language.Haskell.TH.TypeGraph.Monad -- | Build the vertices that involve a particular type - if the field is -- specified it return s singleton, otherwise it returns a set containing -- a vertex one for the type on its own, and one for each field -- containing that type. fieldVertices :: MonadReader (TypeGraphInfo hint) m => TypeGraphVertex -> m (Set TypeGraphVertex) allVertices :: (Functor m, DsMonad m, MonadReader (TypeGraphInfo hint) m) => Maybe Field -> E Type -> m (Set TypeGraphVertex) -- | Build a vertex from the given Type and optional Field. vertex :: (DsMonad m, MonadReader (TypeGraphInfo hint) m) => Maybe Field -> E Type -> m TypeGraphVertex -- | Build a non-field vertex typeVertex :: MonadReader (TypeGraphInfo hint) m => E Type -> m TypeGraphVertex -- | Build a vertex associated with a field fieldVertex :: MonadReader (TypeGraphInfo hint) m => E Type -> Field -> m TypeGraphVertex -- | Start with the type graph on the known types, and build a new graph -- which incorporates the information from the hints. typeGraphEdges :: (DsMonad m, Default hint, Eq hint, HasVertexHints hint, MonadReader (TypeGraphInfo hint) m) => m (GraphEdges hint TypeGraphVertex) -- | Simplify a graph by throwing away the field information in each node. -- This means the nodes only contain the fully expanded Type value (and -- any type synonyms.) simpleEdges :: GraphEdges hint TypeGraphVertex -> GraphEdges hint TypeGraphVertex simpleVertex :: TypeGraphVertex -> TypeGraphVertex module Language.Haskell.TH.TypeGraph.Free freeTypeVars :: (FreeTypeVars t, Quasi m) => t -> m (Set Name) instance FreeTypeVars (Name, Strict, Type) instance FreeTypeVars (Strict, Type) instance FreeTypeVars Con instance FreeTypeVars Type instance FreeTypeVars a => FreeTypeVars [a] instance Show St module Language.Haskell.TH.TypeGraph