-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Graph of the subtype relation -- -- Build a graph whose nodes are Types and whose edges represent the -- subtype relation: Char is a subtype of Maybe Char, Int is a subtype of -- (Int, Double), and so on. @package th-typegraph @version 0.23 module Language.Haskell.TH.TypeGraph.Prelude -- | 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] unlifted :: (IsUnlifted t, Quasi m) => t -> m Bool constructorName :: Con -> Name declarationName :: Dec -> Maybe Name declarationType :: Dec -> Maybe Type class HasSet a m getSet :: HasSet a m => m (Set a) modifySet :: HasSet a m => (Set a -> Set a) -> m () unReify :: Data a => a -> a unReifyName :: Name -> Name -- | Return a key's list of adjacent keys adjacent' :: (Graph, Vertex -> (node, key, [key]), key -> Maybe Vertex) -> key -> [key] -- | Return a key's list of reachable keys reachable' :: (Graph, Vertex -> (node, key, [key]), key -> Maybe Vertex) -> key -> [key] newtype L a L :: a -> L a instance Language.Haskell.TH.Ppr.Ppr () instance Language.Haskell.TH.Ppr.Ppr a => Language.Haskell.TH.Ppr.Ppr (Language.Haskell.TH.TypeGraph.Prelude.L [a]) instance Language.Haskell.TH.TypeGraph.Prelude.IsUnlifted Language.Haskell.TH.Syntax.Dec instance Language.Haskell.TH.TypeGraph.Prelude.IsUnlifted Language.Haskell.TH.Syntax.Con instance Language.Haskell.TH.TypeGraph.Prelude.IsUnlifted Language.Haskell.TH.Syntax.Type instance Language.Haskell.TH.TypeGraph.Prelude.IsUnlifted Language.Haskell.TH.Syntax.Info instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Data.Set.Base.Set a) instance (Language.Haskell.TH.Syntax.Lift a, Language.Haskell.TH.Syntax.Lift b) => Language.Haskell.TH.Syntax.Lift (Data.Map.Base.Map a b) module Language.Haskell.TH.TypeGraph.Free -- | Return the names of the type variables that are free in x. I.e., type -- variables that appear in the type expression but are not bound by an -- enclosing forall or by the type parameters of a Dec. freeTypeVars :: (FreeTypeVars t, Quasi m) => t -> m (Set 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. I'm not quite -- sure I understand the relationship between this and -- freeTypeVars. typeArity :: Quasi m => Type -> m Int instance Language.Haskell.TH.TypeGraph.Free.FreeTypeVars a => Language.Haskell.TH.TypeGraph.Free.FreeTypeVars [a] instance Language.Haskell.TH.TypeGraph.Free.FreeTypeVars Language.Haskell.TH.Syntax.Type instance Language.Haskell.TH.TypeGraph.Free.FreeTypeVars Language.Haskell.TH.Syntax.Con instance Language.Haskell.TH.TypeGraph.Free.FreeTypeVars (Language.Haskell.TH.Syntax.Strict, Language.Haskell.TH.Syntax.Type) instance Language.Haskell.TH.TypeGraph.Free.FreeTypeVars (Language.Haskell.TH.Syntax.Name, Language.Haskell.TH.Syntax.Strict, Language.Haskell.TH.Syntax.Type) instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Free.St -- | 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 GHC.Show.Show a => GHC.Show.Show (Language.Haskell.TH.TypeGraph.Expand.E a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Language.Haskell.TH.TypeGraph.Expand.E a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Language.Haskell.TH.TypeGraph.Expand.E a) instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.PkgName instance Language.Haskell.TH.TypeGraph.Expand.Expanded Language.Haskell.TH.Syntax.Type (Language.Haskell.TH.TypeGraph.Expand.E Language.Haskell.TH.Syntax.Type) instance Language.Haskell.TH.Ppr.Ppr a => Language.Haskell.TH.Ppr.Ppr (Language.Haskell.TH.TypeGraph.Expand.E a) instance Language.Haskell.TH.Syntax.Lift (Language.Haskell.TH.TypeGraph.Expand.E Language.Haskell.TH.Syntax.Type) instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.ModName instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.TyVarBndr instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.NameSpace instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.OccName instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.NameFlavour instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.TyLit instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.Name instance Data.Function.Memoize.Class.Memoizable Language.Haskell.TH.Syntax.Type -- | A fold on the shape of a record. module Language.Haskell.TH.TypeGraph.Shape type Field = (Name, Name, Either Int Name) constructorFields :: Name -> Con -> [Field] data FieldType Positional :: Int -> StrictType -> FieldType Named :: VarStrictType -> FieldType fieldType :: FieldType -> Type constructorFieldTypes :: Con -> [FieldType] fPos :: FieldType -> Either Int Name fName :: FieldType -> Either Int Name fType :: FieldType -> Type -- | 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 instance Data.Data.Data Language.Haskell.TH.TypeGraph.Shape.FieldType instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Shape.FieldType instance GHC.Classes.Ord Language.Haskell.TH.TypeGraph.Shape.FieldType instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.Shape.FieldType instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.Shape.Field instance Language.Haskell.TH.Ppr.Ppr (GHC.Base.Maybe Language.Haskell.TH.TypeGraph.Shape.Field, Language.Haskell.TH.TypeGraph.Expand.E Language.Haskell.TH.Syntax.Type) instance Language.Haskell.TH.Ppr.Ppr (GHC.Base.Maybe Language.Haskell.TH.TypeGraph.Shape.Field, Language.Haskell.TH.Syntax.Type) instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.Shape.FieldType module Language.Haskell.TH.TypeGraph.Vertex class TypeGraphVertex v -- | 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 v => v -> Set Name bestType :: TypeGraphVertex v => v -> Type -- | A vertex of the type graph. Includes a type and (optionally) what -- field of a parent type holds that type. This allows special treatment -- of a type depending on the type that contains it. data TGV TGV :: Maybe Field -> TGVSimple -> TGV -- | The record field which contains this type [_field] :: TGV -> Maybe Field [_vsimple] :: TGV -> TGVSimple field :: Lens' TGV (Maybe Field) vsimple :: Lens' TGV TGVSimple -- | For simple type graphs where no parent field information is required. data TGVSimple TGVSimple :: Set Name -> E Type -> TGVSimple -- | All the type synonyms that expand to this type [_syns] :: TGVSimple -> Set Name -- | The fully expanded type [_etype] :: TGVSimple -> E Type syns :: Lens' TGVSimple (Set Name) etype :: Lens' TGVSimple (E Type) instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.Vertex.TGVSimple instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.Vertex.TGV instance Language.Haskell.TH.Syntax.Lift Language.Haskell.TH.TypeGraph.Vertex.TGV instance Language.Haskell.TH.Syntax.Lift Language.Haskell.TH.TypeGraph.Vertex.TGVSimple instance Language.Haskell.TH.TypeGraph.Vertex.TypeGraphVertex Language.Haskell.TH.TypeGraph.Vertex.TGV instance Language.Haskell.TH.TypeGraph.Vertex.TypeGraphVertex Language.Haskell.TH.TypeGraph.Vertex.TGVSimple instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Vertex.TGV instance GHC.Classes.Ord Language.Haskell.TH.TypeGraph.Vertex.TGV instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.Vertex.TGV instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Vertex.TGVSimple instance GHC.Classes.Ord Language.Haskell.TH.TypeGraph.Vertex.TGVSimple instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.Vertex.TGVSimple module Language.Haskell.TH.TypeGraph.Info -- | Information collected about the graph implied by the structure of one -- or more Type values. data TypeInfo startTypes :: Lens' TypeInfo [Type] fields :: Lens' TypeInfo (Map (E Type) (Set (Name, Name, Either Int Name))) infoMap :: Lens' TypeInfo (Map Name Info) synonyms :: Lens' TypeInfo (Map (E Type) (Set Name)) typeSet :: Lens' TypeInfo (Set Type) -- | Build a TypeInfo value by scanning the supplied types makeTypeInfo :: DsMonad m => (Type -> m (Set Type)) -> [Type] -> m TypeInfo -- | Build a vertex from the given Type and optional Field. -- vertex :: forall m. (DsMonad m, MonadReader TypeInfo m) => Maybe -- Field -> E Type -> m TypeGraphVertex vertex fld etyp = maybe -- (typeVertex etyp) (fieldVertex etyp) fld -- -- Build a non-field vertex typeVertex :: MonadReader TypeInfo m => E Type -> m TGVSimple typeVertex' :: MonadReader TypeInfo m => E Type -> m TGV -- | Build a vertex associated with a field fieldVertex :: MonadReader TypeInfo m => Field -> E Type -> m TGV -- | Find 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 TypeInfo m => TGVSimple -> m (Set TGV) allVertices :: (Functor m, DsMonad m, MonadReader TypeInfo m) => Maybe Field -> E Type -> m (Set TGV) instance Language.Haskell.TH.Syntax.Lift Language.Haskell.TH.TypeGraph.Info.TypeInfo instance GHC.Classes.Ord Language.Haskell.TH.TypeGraph.Info.TypeInfo instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.Info.TypeInfo instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Info.TypeInfo instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.Info.TypeInfo -- | 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 Language.Haskell.TH.TypeGraph.Expand.Expanded Language.Haskell.TH.Syntax.Type Language.Haskell.TH.Syntax.Type -- | Operations involving the edges of the graph (before it is a graph.) module Language.Haskell.TH.TypeGraph.Edges type GraphEdges key = Map key (Set key) -- | Given the discovered set of types and maps of type synonyms and -- fields, build and return the GraphEdges relation on TypeGraphVertex. -- This is not a recursive function, it stops when it reaches the field -- types. typeGraphEdges :: (DsMonad m, Functor m, MonadReader TypeInfo m) => m (GraphEdges TGV) -- | Isolate and remove matching nodes cut :: (Eq a, Ord a) => (a -> Bool) -> GraphEdges a -> GraphEdges a -- | Monadic predicate version of cut. cutM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges a -> m (GraphEdges a) cutEdges :: (Eq a, Ord a) => (a -> a -> Bool) -> GraphEdges a -> (GraphEdges a) cutEdgesM :: (Monad m, Eq a, Ord a) => (a -> a -> m Bool) -> GraphEdges a -> m (GraphEdges a) -- | Remove all the in- and out-edges of matching nodes isolate :: (Eq a, Ord a) => (a -> Bool) -> GraphEdges a -> GraphEdges a -- | Monadic predicate version of isolate. isolateM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges a -> m (GraphEdges a) -- | Replace the out set of selected nodes link :: (Eq a, Ord a) => (a -> Maybe (Set a)) -> GraphEdges a -> GraphEdges a linkM :: (Eq a, Ord a, Monad m) => (a -> m (Maybe (Set a))) -> GraphEdges a -> m (GraphEdges a) -- | Remove matching nodes and extend each of their in-edges to each of -- their out-edges. dissolve :: (Eq a, Ord a) => (a -> Bool) -> GraphEdges a -> GraphEdges a -- | Monadic predicate version of dissolve. dissolveM :: (Functor m, Monad m, Eq a, Ord a) => (a -> m Bool) -> GraphEdges a -> m (GraphEdges a) -- | 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 TGV -> GraphEdges TGVSimple instance Language.Haskell.TH.Ppr.Ppr key => Language.Haskell.TH.Ppr.Ppr (Language.Haskell.TH.TypeGraph.Edges.GraphEdges key) -- | The HasStack monad used in MIMO to construct lenses that look deep -- into a record type. However, it does not involve the Path type -- mechanism, and is unaware of View instances and other things that -- modify the type graph. Lets see how it adapts. module Language.Haskell.TH.TypeGraph.Stack class Monad m => HasStack m withStack :: HasStack m => ([StackElement] -> m a) -> m a push :: HasStack m => FieldType -> Con -> Dec -> m a -> m a newtype Wrapper a Wrapper :: a -> Wrapper a unwrap :: Iso (Wrapper a_awtL) (Wrapper a_awCR) a_awtL a_awCR -- | The information required to extact a field value from a value. We keep -- a stack of these as we traverse a declaration. Generally, we only need -- the field names. data StackElement StackElement :: FieldType -> Con -> Dec -> StackElement prettyStack :: [StackElement] -> String -- | Push the stack and process the field. foldField :: HasStack m => (FieldType -> m r) -> Dec -> Con -> FieldType -> m r type StackT m = ReaderT [StackElement] m execStackT :: Monad m => StackT m a -> m a -- | Re-implementation of stack accessor in terms of stackLens stackAccessor :: (Quasi m, HasStack m) => ExpQ -> Type -> m Exp -- | Generate lenses to access the fields of the row types. Like -- Control.Lens.TH.makeLenses, but makes lenses for every field, and -- instead of removing the prefix '_' to form the lens name it adds the -- prefix "lens" and capitalizes the first letter of the field. The only -- reason for this function is backwards compatibility, the fields should -- be changed so they begin with _ and the regular makeLenses should be -- used. makeLenses' :: (Type -> Q (Set Type)) -> [Name] -> Q [Dec] traceIndented :: HasStack m => String -> m () instance (Language.Haskell.TH.TypeGraph.Stack.HasStack m, GHC.Base.Monoid w) => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.Writer.Lazy.WriterT w m) instance Data.Data.Data Language.Haskell.TH.TypeGraph.Stack.StackElement instance GHC.Show.Show Language.Haskell.TH.TypeGraph.Stack.StackElement instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.Stack.StackElement instance (Language.Haskell.TH.Syntax.Quasi m, GHC.Base.Monoid w) => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.RWS.Lazy.RWST [Language.Haskell.TH.TypeGraph.Stack.StackElement] w s m) instance Language.Haskell.TH.TypeGraph.Stack.HasStack m => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.State.Lazy.StateT s m) instance Language.Haskell.TH.Syntax.Quasi m => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.Reader.ReaderT [Language.Haskell.TH.TypeGraph.Stack.StackElement] m) instance Language.Haskell.TH.TypeGraph.Stack.HasStack m => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.Reader.ReaderT (Language.Haskell.TH.TypeGraph.Stack.Wrapper a) m) -- | Abstract operations on Maps containing graph edges. module Language.Haskell.TH.TypeGraph.Graph data TypeGraph typeInfo :: Lens' TypeGraph TypeInfo edges :: Lens' TypeGraph (GraphEdges TGV) graph :: Lens' TypeGraph (Graph, Vertex -> ((), TGV, [TGV]), TGV -> Maybe Vertex) gsimple :: Lens' TypeGraph (Graph, Vertex -> ((), TGVSimple, [TGVSimple]), TGVSimple -> Maybe Vertex) stack :: Lens' TypeGraph [StackElement] -- | 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 key -> (Graph, Vertex -> ((), key, [key]), key -> Maybe Vertex) -- | Lenses represent steps in a path, but the start point is a type vertex -- and the endpoint is a field vertex. allLensKeys :: (DsMonad m, MonadReader TypeGraph m) => m (Map TGVSimple (Set TGV)) -- | Paths go between simple types. allPathKeys :: (DsMonad m, MonadReader TypeGraph m) => m (Map TGVSimple (Set TGVSimple)) allPathStarts :: (DsMonad m, MonadReader TypeGraph m) => m (Set TGV) reachableFrom :: (DsMonad m, MonadReader TypeGraph m) => TGV -> m (Set TGV) reachableFromSimple :: (DsMonad m, MonadReader TypeGraph m) => TGVSimple -> m (Set TGVSimple) -- | Can we reach the goal type from the start type in this key? goalReachableFull :: (Functor m, DsMonad m, MonadReader TypeGraph m) => TGV -> TGV -> m Bool goalReachableSimple :: (Functor m, DsMonad m, MonadReader TypeGraph m) => TGVSimple -> TGVSimple -> m Bool goalReachableSimple' :: (Functor m, DsMonad m, MonadReader TypeGraph m) => TGV -> TGV -> m Bool makeTypeGraph :: MonadReader TypeInfo m => (GraphEdges TGV) -> m TypeGraph -- | When a VertexStatus value is associated with a Type it describes -- alterations in the type graph from the usual default. data VertexStatus typ -- | normal case Vertex :: VertexStatus typ -- | out degree zero - don't create any outgoing edges Sink :: VertexStatus typ -- | replace all outgoing edges with an edge to an alternate type Divert :: typ -> VertexStatus typ -- | add an extra outgoing edge to the given type Extra :: typ -> VertexStatus typ -- | Return the set of edges implied by the subtype relationship among a -- set of types. This is just the nodes of the type graph. The type -- aliases are expanded by the th-desugar package to make them suitable -- for use as map keys. typeGraphEdges' :: (DsMonad m, MonadReader TypeGraph m, HasSet TGV m) => (TGV -> m (Set TGV)) -> [Type] -> m (GraphEdges TGV) -- | Return the set of adjacent vertices according to the default type -- graph - i.e. the one determined only by the type definitions, not by -- any additional hinting function. adjacent :: (MonadReader TypeGraph m, DsMonad m) => TGV -> m (Set TGV) -- | Return the TGV associated with a particular type, with no field -- specified. typeGraphVertex :: (MonadReader TypeGraph m, DsMonad m) => Type -> m TGV -- | Return the TGV associated with a particular type and field. typeGraphVertexOfField :: (MonadReader TypeGraph m, DsMonad m) => (Name, Name, Either Int Name) -> Type -> m TGV instance GHC.Show.Show typ => GHC.Show.Show (Language.Haskell.TH.TypeGraph.Graph.VertexStatus typ) instance GHC.Base.Monad m => Language.Haskell.TH.TypeGraph.Stack.HasStack (Control.Monad.Trans.Reader.ReaderT Language.Haskell.TH.TypeGraph.Graph.TypeGraph m) instance Data.Default.Class.Default (Language.Haskell.TH.TypeGraph.Graph.VertexStatus typ) instance Language.Haskell.TH.Ppr.Ppr Data.Graph.Vertex