/usr/share/doc/libghc-th-reify-many-doc/html/th-reify-many.txt is in libghc-th-reify-many-doc 0.1.8-1build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | -- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Recurseively reify template haskell datatype info
--
-- <tt>th-reify-many</tt> provides functions for recursively reifying top
-- level declarations. The main intended use case is for enumerating the
-- names of datatypes reachable from an initial datatype, and passing
-- these names to some function which generates instances.
@package th-reify-many
@version 0.1.8
module Language.Haskell.TH.ReifyMany.Internal
-- | Returns <a>True</a> if the <a>Dec</a> is a <a>DataD</a> or
-- <a>NewtypeD</a>
isDataDec :: Dec -> Bool
-- | Returns <a>True</a> if the <a>Dec</a> is a <a>DataD</a>,
-- <a>NewtypeD</a>, or <a>TySynD</a>.
isNormalTyCon :: Dec -> Bool
-- | For data, newtype, and type declarations, yields a list of the types
-- of the fields. In the case of a type synonyms, it just returns the
-- body of the type synonym as a singleton list.
decToFieldTypes :: Dec -> [[Type]]
-- | Returns the types of the fields of the constructor.
conToFieldTypes :: Con -> [Type]
-- | Returns the names of all type constructors which aren't involved in
-- constraints.
typeConcreteNames :: Type -> [Name]
-- | Returns the names of all type constructors used when defining type
-- constructors.
decConcreteNames :: Dec -> [Name]
-- | Datatype to capture the fields of <a>InstanceD</a>.
data TypeclassInstance
TypeclassInstance :: Cxt -> Type -> [Dec] -> TypeclassInstance
-- | Given the <a>Name</a> of a class, yield all of the
-- <a>TypeclassInstance</a>s, with synonyms expanded in the <a>Type</a>
-- field.
getInstances :: Name -> Q [TypeclassInstance]
-- | Returns the first <a>TypeclassInstance</a> where
-- <a>instanceMatches</a> returns true.
lookupInstance :: [TypeclassInstance] -> Name -> Maybe TypeclassInstance
-- | Checks if the given name is the head of one of the paramaters of the
-- given <a>TypeclassInstance</a>.
instanceMatches :: TypeclassInstance -> Name -> Bool
-- | Breaks a type application like <tt>A b c</tt> into [A, b, c].
unAppsT :: Type -> [Type]
instance GHC.Show.Show Language.Haskell.TH.ReifyMany.Internal.TypeclassInstance
-- | <tt>th-reify-many</tt> provides functions for recursively reifying top
-- level declarations. The main intended use case is for enumerating the
-- names of datatypes reachable from an initial datatype, and passing
-- these names to some function which generates instances.
--
-- For example, in order to define <a>Lift</a> instances for two mutually
-- recursive datatypes, I could write something like:
--
-- <pre>
-- {-# LANGUAGE TemplateHaskell #-}
-- import Language.Haskell.TH.ReifyMany (reifyManyWithoutInstances)
-- import Language.Haskell.TH.Lift (Lift(..), deriveLiftMany)
--
-- data A = A B
--
-- data B = B Int
--
-- $(reifyManyWithoutInstances ''Lift [''A] (const True) >>= deriveLiftMany)
-- </pre>
--
-- One interesting feature of this is that it attempts to omit the types
-- which already have an instance defined. For example, if
-- <tt>$(deriveLift ''B)</tt> is used before <tt>deriveLiftMany</tt>, it
-- will omit the instance for B.
--
-- Of course, the intended usecase for this involves many more datatypes
-- - for example, syntax trees such as those found in TH.
--
-- Note that <a>reifyManyWithoutInstances</a> is rather imperfect in its
-- testing of whether an instance exists, and whether an instance should
-- exist. See this function's docs for details.
module Language.Haskell.TH.ReifyMany
-- | Recursively enumerates type constructor declarations, halting when
-- datatypes appear to already have an instance for the typeclass
-- specified by the first <a>Name</a> parameter. It guesses that an
-- instance exists for a given datatype if it's used in the top
-- constructor of any of its parameters (see <a>instanceMatches</a>).
--
-- This function is useful for bulk defining typeclass instances like
-- <tt>Binary</tt>, <tt>Lift</tt>, <tt>Data</tt>, <tt>Typeable</tt>, etc.
-- It isn't very clever, though - in particular it has the following
-- limitations:
--
-- <ul>
-- <li>It only works well when type constructors mentioned in fields
-- should all have instances defined for them.</li>
-- <li>It ignores data type / constructor constraints.</li>
-- <li>It ignores data / type families.</li>
-- </ul>
--
-- It also takes a user-defined predicate, which is useful in situations
-- where this attempts to descend into datatypes which do not need
-- instances defined for them.
--
-- Note that this will always initially yield the <a>Name</a>s of the
-- initial types, regardless of whether they are instances or not.
reifyManyWithoutInstances :: Name -> [Name] -> (Name -> Bool) -> Q [Name]
-- | Like <a>reifyMany</a>, but specialized for recursively enumerating
-- type constructor declarations, omitting <a>PrimTyConI</a>.
--
-- In order to have this behave like <a>reifyManyWithoutInstances</a>,
-- but not do any instance filtering, use it with the <a>isDataDec</a>
-- and <a>decConcreteNames</a> internal utilities. For example:
--
-- <pre>
-- {-# LANGUAGE TemplateHaskell #-}
-- import Language.Haskell.TH
-- import Language.Haskell.TH.ReifyMany
-- import Language.Haskell.TH.ReifyMany.Internal
--
-- $(do results <- reifyManyTyCons
-- (\(_, dec) -> return (isDataDec dec, decConcreteNames dec))
-- [''Exp]
-- -- Display the results
-- reportError (show (map fst results))
-- -- This TH splice doesn't generate any code.
-- return []
-- )
-- </pre>
reifyManyTyCons :: ((Name, Dec) -> Q (Bool, [Name])) -> [Name] -> Q [(Name, Info)]
-- | Starting from a set of initial top level declarations, specified by
-- <tt>[Name]</tt>, recursively enumerate other related declarations. The
-- provided function determines whether the current info be included in
-- the list of results, and which <a>Name</a>s to lookup next. This
-- function handles keeping track of which <a>Name</a>s have already been
-- visited.
reifyMany :: ((Name, Info) -> Q (Bool, [Name])) -> [Name] -> Q [(Name, Info)]
|