-- 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.28 -- | 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 -- | A concrete type used to mark type which have been expanded newtype E a E :: a -> E a [unE] :: E a -> a -- | The state type used to memoize expansions. type ExpandMap = Map Type (E Type) -- | Apply the th-desugar expand function to a Type and mark it as -- expanded. expandType :: (DsMonad m, MonadStates ExpandMap m) => Type -> m (E Type) -- | 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, MonadStates ExpandMap m) => Type -> m (E Type) -- | Expand a list of Type and build an expanded ClassP -- Pred. expandClassP :: (DsMonad m, MonadStates ExpandMap m) => Name -> [Type] -> m (E Type) 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 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) 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 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) -- | Function to compute free type variable set for a Type. (I took this -- from somewhere, I really need to credit it. Now when I search all I -- can find is myself.) 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) 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 -- | A fold on the shape of the constructors of a DataD or NewtypeD 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.TypeInfo -- | 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, MonadReaders TypeInfo m) => Maybe -- Field -> E Type -> m TypeGraphVertex vertex fld etyp = maybe -- (typeVertex etyp) (fieldVertex etyp) fld -- -- Build a non-field vertex typeVertex :: MonadReaders TypeInfo m => E Type -> m TGVSimple typeVertex' :: MonadReaders TypeInfo m => E Type -> m TGV -- | Build a vertex associated with a field fieldVertex :: MonadReaders 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 :: MonadReaders TypeInfo m => TGVSimple -> m (Set TGV) allVertices :: (Functor m, DsMonad m, MonadReaders TypeInfo m) => Maybe Field -> E Type -> m (Set TGV) instance GHC.Base.Monad m => Control.Monad.States.MonadStates Language.Haskell.TH.TypeGraph.Expand.ExpandMap (Control.Monad.Trans.State.Lazy.StateT Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo m) instance Language.Haskell.TH.Syntax.Lift Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo instance GHC.Classes.Ord Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo instance GHC.Classes.Eq Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo instance GHC.Show.Show Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo instance Language.Haskell.TH.Ppr.Ppr Language.Haskell.TH.TypeGraph.TypeInfo.TypeInfo -- | 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, MonadReaders TypeInfo m, MonadStates ExpandMap 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 -- | 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 :: MonadReaders [StackElement] m => (FieldType -> m r) -> Dec -> Con -> FieldType -> m r type HasStack = MonadReaders [StackElement] type StackT m = ReaderT [StackElement] m execStackT :: Monad m => StackT m a -> m a withStack :: (Monad m, MonadReaders [StackElement] m) => ([StackElement] -> m a) -> m a push :: MonadReaders [StackElement] m => FieldType -> Con -> Dec -> m a -> m a -- | Return a lambda function that turns a value of Type typ0 into the type -- implied by the stack elements. stackAccessor :: (Quasi m, MonadReaders [StackElement] m) => m Exp traceIndented :: MonadReaders [StackElement] m => String -> m () -- | Given a field name, return the name to use for the corresponding lens. lensNamer :: String -> String 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 -- | Abstract operations on Maps containing graph edges. module Language.Haskell.TH.TypeGraph.TypeGraph 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, MonadStates (Map Type (E Type)) m, MonadReaders TypeGraph m) => m (Map TGVSimple (Set TGV)) -- | Paths go between simple types. allPathKeys :: (DsMonad m, MonadStates (Map Type (E Type)) m, MonadReaders TypeGraph m) => m (Map TGVSimple (Set TGVSimple)) allPathStarts :: (DsMonad m, MonadStates (Map Type (E Type)) m, MonadReaders TypeGraph m) => m (Set TGV) reachableFrom :: (DsMonad m, MonadReaders TypeGraph m) => TGV -> m (Set TGV) reachableFromSimple :: (DsMonad m, MonadReaders TypeGraph m) => TGVSimple -> m (Set TGVSimple) -- | Can we reach the goal type from the start type in this key? goalReachableFull :: (Functor m, DsMonad m, MonadReaders TypeGraph m) => TGV -> TGV -> m Bool goalReachableSimple :: (Functor m, DsMonad m, MonadReaders TypeGraph m) => TGVSimple -> TGVSimple -> m Bool goalReachableSimple' :: (Functor m, DsMonad m, MonadReaders TypeGraph m) => TGV -> TGV -> m Bool makeTypeGraph :: MonadReaders 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, MonadReaders TypeGraph m, MonadStates (Set TGV) m, MonadStates (Map Type (E Type)) 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 :: (MonadReaders TypeGraph m, DsMonad m, MonadStates (Map Type (E Type)) m) => TGV -> m (Set TGV) -- | Return the TGV associated with a particular type, with no field -- specified. typeGraphVertex :: (MonadReaders TypeGraph m, MonadStates ExpandMap m, DsMonad m) => Type -> m TGV -- | Return the TGV associated with a particular type and field. typeGraphVertexOfField :: (MonadReaders TypeGraph m, MonadStates (Map Type (E Type)) m, DsMonad m) => (Name, Name, Either Int Name) -> Type -> m TGV instance GHC.Show.Show typ => GHC.Show.Show (Language.Haskell.TH.TypeGraph.TypeGraph.VertexStatus typ) instance (GHC.Base.Monad m, Control.Monad.Readers.MonadReaders [Language.Haskell.TH.TypeGraph.Stack.StackElement] m) => Control.Monad.Readers.MonadReaders [Language.Haskell.TH.TypeGraph.Stack.StackElement] (Control.Monad.Trans.Reader.ReaderT Language.Haskell.TH.TypeGraph.TypeGraph.TypeGraph m) instance Data.Default.Class.Default (Language.Haskell.TH.TypeGraph.TypeGraph.VertexStatus typ) instance Language.Haskell.TH.Ppr.Ppr Data.Graph.Vertex -- | 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.Lens -- | 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, makeLensesFor -- should be used instead. makeTypeGraphLenses :: (DsMonad m, MonadStates ExpandMap m, MonadReaders [StackElement] m, MonadReaders TypeGraph m) => m [Dec] -- | Build the list of pairs used by makeLensesFor. lensNamePairs :: Quasi m => (Name -> Name -> Name -> (String, String)) -> Name -> m [(String, String)] -- | Function to compute the arity or kind of a Type, the number of type -- parameters that need to be applied to get a concrete type. module Language.Haskell.TH.TypeGraph.Arity -- | 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