-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Graph of the subtype relation -- -- This package is not the successor to th-typegraph-0.43, it is a brand -- new package which forms the basis of a new package that what will -- eventually do what th-typegraph was supposed to. What it *can* do is -- traverse the type TypeQ, and includes versions of -- deriveSafeCopy and derivePathInfo that use the traversal to avoid -- adding phantom types to the context of the instance. @package th-typegraph @version 1.0.2 module Language.Haskell.TH.TypeGraph.Orphans -- | Int is the ContainerKey type for all lists, so we need -- to make sure all the required instances exist. instance Language.Haskell.TH.Syntax.Lift a0 => Language.Haskell.TH.Syntax.Lift (Data.Graph.Inductive.NodeMap.NodeMap a0) instance (Language.Haskell.TH.Syntax.Lift a0, Language.Haskell.TH.Syntax.Lift b0) => Language.Haskell.TH.Syntax.Lift (Data.Graph.Inductive.PatriciaTree.Gr a0 b0) instance Language.Haskell.TH.Syntax.Lift Data.UserId.UserId instance Data.Serialize.Serialize Data.UserId.UserId instance Data.Serialize.Serialize Language.Haskell.TH.Syntax.Loc instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.Loc instance Data.Serialize.Serialize Data.Time.Clock.UTC.UTCTime instance Data.Serialize.Serialize Data.Time.Calendar.Days.Day instance Data.Serialize.Serialize Data.Time.Clock.Scale.DiffTime instance Data.Aeson.Types.FromJSON.FromJSONKey Data.UserId.UserId instance Data.Aeson.Types.ToJSON.ToJSONKey Data.UserId.UserId instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.Name instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.NameFlavour instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.ModName instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.PkgName instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.NameSpace instance Data.SafeCopy.SafeCopy.SafeCopy Language.Haskell.TH.Syntax.OccName instance Language.Haskell.TH.Ppr.Ppr () instance Language.Haskell.TH.Ppr.Ppr GHC.Types.Int instance Language.Haskell.TH.Ppr.Ppr (Data.Set.Base.Set Language.Haskell.TH.Syntax.Type, Data.Set.Base.Set Language.Haskell.TH.Syntax.Type) instance Language.Haskell.TH.Ppr.Ppr (Data.Set.Base.Set Language.Haskell.TH.Syntax.Type) instance Data.SafeCopy.SafeCopy.SafeCopy (Data.Proxy.Proxy t) -- | Build a directed graph whose nodes are arity zero types and whose -- edges represent the hops in the path graph. module Language.Haskell.TH.TypeGraph.TypeTraversal class DsMonad m => HasVisitedMap m unvisited :: HasVisitedMap m => Type -> m () -> m () doType :: HasTypeTraversal m => Type -> m () class Monad m => HasTypeParameters m pushParam :: HasTypeParameters m => Type -> m a -> m a withParams :: HasTypeParameters m => ([Type] -> m ()) -> m () -- | Input is a list of type variable bindings (such as those appearing in -- a Dec) and the current stack of type parameters applied by AppT. -- Builds a function that expands a type using those bindings and pass it -- to an action. withBindings :: (HasTypeParameters m, Data a) => ((a -> a) -> m ()) -> [TyVarBndr] -> m () class (DsMonad m, HasVisitedMap m) => HasTypeTraversal m -- | Normally just return, this can modify the types during the -- traversal. prepType :: HasTypeTraversal m => Type -> m Type -- | This is passed every type that is encountered. The methods below are -- called from doApply. doTypeInternal :: HasTypeTraversal m => Type -> m () -- | When a ListT type is encountered this is passed the type and the -- element type doListT :: HasTypeTraversal m => Type -> Type -> m () -- | When a TupleT type is encountered this is called once for each -- element, with the type, element type, and element position. doTupleT :: HasTypeTraversal m => Type -> Type -> Int -> m () -- | When a field is encountered this is called with all the field info - -- type name, constructor countpositionname, field -- countpositiontype/maybe name. doField :: HasTypeTraversal m => Type -> (Type -> Type) -> FieldInfo -> m () -- | Called when a type variable is encountered. doVarT :: HasTypeTraversal m => Type -> Name -> m () doApply :: (HasTypeTraversal m, HasTypeParameters m, DsMonad m) => Type -> Type -> m () data FieldInfo FieldInfo :: Name -> Int -> Int -> Name -> Int -> Int -> Maybe Name -> Type -> FieldInfo [_typeName] :: FieldInfo -> Name [_constrCount] :: FieldInfo -> Int [_constrIndex] :: FieldInfo -> Int [_constrName] :: FieldInfo -> Name [_fieldCount] :: FieldInfo -> Int [_fieldIndex] :: FieldInfo -> Int [_fieldName] :: FieldInfo -> Maybe Name [_fieldType] :: FieldInfo -> Type expandType :: DsMonad m => Type -> m Type -- | Pretty print a Ppr value on a single line with each block of -- white space (newlines, tabs, etc.) converted to a single space, and -- all the module qualifiers removed from the names. (If the data type -- has no Name values the friendlyNames function has no effect.) pprint1 :: (Ppr a, Data a) => a -> [Char] pprint1' :: Ppr a => a -> [Char] -- | Pretty print with friendly names and wide lines pprintW :: (Ppr a, Data a) => Int -> a -> [Char] pprintW' :: Ppr a => Int -> a -> [Char] -- | Copied from haskell-src-meta class ToName a toName :: ToName a => a -> Name class HasMessageInfo a verbosity' :: HasMessageInfo a => Lens' a Int prefix' :: HasMessageInfo a => Lens' a String -- | Output a verbosity controlled error message with the current -- indentation. message :: (Quasi m, MonadReader s m, HasMessageInfo s) => Int -> String -> m () -- | Indent the lines of a message. indent :: String -> String -> String instance GHC.Show.Show Language.Haskell.TH.TypeGraph.TypeTraversal.FieldInfo instance Language.Haskell.TH.TypeGraph.TypeTraversal.ToName Language.Haskell.TH.Syntax.TyVarBndr instance Language.Haskell.TH.TypeGraph.TypeTraversal.ToName Language.Haskell.TH.Syntax.Con instance Language.Haskell.TH.TypeGraph.TypeTraversal.ToName Language.Haskell.TH.Syntax.VarStrictType -- | Compute which type parameters are phantom types. module Language.Haskell.TH.TypeGraph.Phantom nonPhantom :: DsMonad m => Name -> m [Type] instance GHC.Base.Monad m => Language.Haskell.TH.TypeGraph.TypeTraversal.HasTypeParameters (Language.Haskell.TH.TypeGraph.Phantom.PathT m) instance Language.Haskell.TH.TypeGraph.TypeTraversal.HasMessageInfo Language.Haskell.TH.TypeGraph.Phantom.R instance Language.Haskell.TH.Desugar.Reify.DsMonad m => Language.Haskell.TH.TypeGraph.TypeTraversal.HasVisitedMap (Control.Monad.Trans.RWS.Lazy.RWST Language.Haskell.TH.TypeGraph.Phantom.R () Language.Haskell.TH.TypeGraph.Phantom.S m) instance Language.Haskell.TH.Desugar.Reify.DsMonad m => Language.Haskell.TH.TypeGraph.TypeTraversal.HasTypeTraversal (Control.Monad.Trans.RWS.Lazy.RWST Language.Haskell.TH.TypeGraph.Phantom.R () Language.Haskell.TH.TypeGraph.Phantom.S m) module Language.Haskell.TH.TypeGraph.SafeCopyDerive -- | FIXME - Bogus reimplementation of the hidden Data.SafeCopy.unVersion -- function unVersion :: Version a -> Int32 -- | Derive an instance of SafeCopy. -- -- When serializing, we put a Word8 describing the constructor -- (if the data type has more than one constructor). For each type used -- in the constructor, we call getSafePut (which immediately -- serializes the version of the type). Then, for each field in the -- constructor, we use one of the put functions obtained in the last -- step. -- -- For example, given the data type and the declaration below -- --
-- data T0 b = T0 b Int -- deriveSafeCopy 1 'base ''T0 -- ---- -- we generate -- --
-- instance (SafeCopy a, SafeCopy b) => -- SafeCopy (T0 b) where -- putCopy (T0 arg1 arg2) = contain $ do put_b <- getSafePut -- put_Int <- getSafePut -- put_b arg1 -- put_Int arg2 -- return () -- getCopy = contain $ do get_b <- getSafeGet -- get_Int <- getSafeGet -- return T0 <*> get_b <*> get_Int -- version = 1 -- kind = base -- ---- -- And, should we create another data type as a newer version of -- T0, such as -- --
-- data T a b = C a a | D b Int -- deriveSafeCopy 2 'extension ''T -- -- instance SafeCopy b => Migrate (T a b) where -- type MigrateFrom (T a b) = T0 b -- migrate (T0 b i) = D b i -- ---- -- we generate -- --
-- instance (SafeCopy a, SafeCopy b) => -- SafeCopy (T a b) where -- putCopy (C arg1 arg2) = contain $ do putWord8 0 -- put_a <- getSafePut -- put_a arg1 -- put_a arg2 -- return () -- putCopy (D arg1 arg2) = contain $ do putWord8 1 -- put_b <- getSafePut -- put_Int <- getSafePut -- put_b arg1 -- put_Int arg2 -- return () -- getCopy = contain $ do tag <- getWord8 -- case tag of -- 0 -> do get_a <- getSafeGet -- return C <*> get_a <*> get_a -- 1 -> do get_b <- getSafeGet -- get_Int <- getSafeGet -- return D <*> get_b <*> get_Int -- _ -> fail $ "Could not identify tag \"" ++ -- show tag ++ "\" for type Main.T " ++ -- "that has only 2 constructors. " ++ -- "Maybe your data is corrupted?" -- version = 2 -- kind = extension -- ---- -- Note that by using getSafePut, we saved 4 bytes in the case of the -- C constructor. For D and T0, we didn't save -- anything. The instance derived by this function always use at most the -- same space as those generated by deriveSafeCopySimple, but -- never more (as we don't call 'getSafePut'/'getSafeGet' for types that -- aren't needed). -- -- Note that you may use deriveSafeCopySimple with one version of -- your data type and deriveSafeCopy in another version without -- any problems. deriveSafeCopy :: Version a -> Name -> Name -> Q [Dec] deriveSafeCopyIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] -- | Derive an instance of SafeCopy. The instance derived by this -- function is simpler than the one derived by deriveSafeCopy in -- that we always use safePut and safeGet (instead of -- getSafePut and getSafeGet). -- -- When serializing, we put a Word8 describing the constructor -- (if the data type has more than one constructor) and, for each field -- of the constructor, we use safePut. -- -- For example, given the data type and the declaration below -- --
-- data T a b = C a a | D b Int -- deriveSafeCopySimple 1 'base ''T -- ---- -- we generate -- --
-- instance (SafeCopy a, SafeCopy b) => -- SafeCopy (T a b) where -- putCopy (C arg1 arg2) = contain $ do putWord8 0 -- safePut arg1 -- safePut arg2 -- return () -- putCopy (D arg1 arg2) = contain $ do putWord8 1 -- safePut arg1 -- safePut arg2 -- return () -- getCopy = contain $ do tag <- getWord8 -- case tag of -- 0 -> do return C <*> safeGet <*> safeGet -- 1 -> do return D <*> safeGet <*> safeGet -- _ -> fail $ "Could not identify tag \"" ++ -- show tag ++ "\" for type Main.T " ++ -- "that has only 2 constructors. " ++ -- "Maybe your data is corrupted?" -- version = 1 -- kind = base -- ---- -- Using this simpler instance means that you may spend more bytes when -- serializing data. On the other hand, it is more straightforward and -- may match any other format you used in the past. -- -- Note that you may use deriveSafeCopy with one version of your -- data type and deriveSafeCopySimple in another version without -- any problems. deriveSafeCopySimple :: Version a -> Name -> Name -> Q [Dec] deriveSafeCopySimpleIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] -- | Derive an instance of SafeCopy. The instance derived by this -- function should be compatible with the instance derived by the module -- Happstack.Data.SerializeTH of the happstack-data -- package. The instances use only safePut and safeGet (as -- do the instances created by deriveSafeCopySimple), but we also -- always write a Word8 tag, even if the data type isn't a sum -- type. -- -- For example, given the data type and the declaration below -- --
-- data T0 b = T0 b Int -- deriveSafeCopy 1 'base ''T0 -- ---- -- we generate -- --
-- instance (SafeCopy a, SafeCopy b) => -- SafeCopy (T0 b) where -- putCopy (T0 arg1 arg2) = contain $ do putWord8 0 -- safePut arg1 -- safePut arg2 -- return () -- getCopy = contain $ do tag <- getWord8 -- case tag of -- 0 -> do return T0 <*> safeGet <*> safeGet -- _ -> fail $ "Could not identify tag \"" ++ -- show tag ++ "\" for type Main.T0 " ++ -- "that has only 1 constructors. " ++ -- "Maybe your data is corrupted?" -- version = 1 -- kind = base -- ---- -- This instance always consumes at least the same space as -- deriveSafeCopy or deriveSafeCopySimple, but may use more -- because of the useless tag. So we recomend using it only if you really -- need to read a previous version in this format, and not for newer -- versions. -- -- Note that you may use deriveSafeCopy with one version of your -- data type and deriveSafeCopyHappstackData in another version -- without any problems. deriveSafeCopyHappstackData :: Version a -> Name -> Name -> Q [Dec] deriveSafeCopyHappstackDataIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] data DeriveType Normal :: DeriveType Simple :: DeriveType HappstackData :: DeriveType forceTag :: DeriveType -> Bool tyVarName :: TyVarBndr -> Name internalDeriveSafeCopy :: DeriveType -> Version a -> Name -> Name -> Q [Dec] internalDeriveSafeCopy' :: DeriveType -> Version a -> Name -> Name -> Info -> Q [Dec] internalDeriveSafeCopyIndexedType :: DeriveType -> Version a -> Name -> Name -> [Name] -> Q [Dec] internalDeriveSafeCopyIndexedType' :: DeriveType -> Version a -> Name -> Name -> [Name] -> Info -> Q [Dec] mkPutCopy :: DeriveType -> [(Integer, Con)] -> DecQ mkGetCopy :: DeriveType -> String -> [(Integer, Con)] -> DecQ mkSafeFunctions :: String -> Name -> Con -> Q ([StmtQ], Type -> Name) -- | Follow type synonyms. This allows us to see, for example, that -- [Char] and String are the same type and we just need -- to call getSafePut or getSafeGet once for both. followSynonyms :: Type -> Q Type conSize :: Con -> Int conName :: Con -> Name conTypes :: Con -> [Type] typeName :: Type -> String -- | Modified version of Web.Routes.TH module Language.Haskell.TH.TypeGraph.WebRoutesTH -- | use Template Haskell to create PathInfo instances for a type. -- --
-- $(derivePathInfo ''SiteURL) ---- -- Uses the standard formatter by default. derivePathInfo :: Name -> Q [Dec] -- | use Template Haskell to create PathInfo instances for a type. -- -- This variant allows the user to supply a function that transforms the -- constructor name to a prettier rendering. It is important that the -- transformation function generates a unique output for each input. For -- example, simply converting the string to all lower case is not -- acceptable, because then FooBar and Foobar would be -- indistinguishable. -- --
-- $(derivePathInfo' standard ''SiteURL) ---- -- see also: standard derivePathInfo' :: (String -> String) -> Name -> Q [Dec] -- | the standard formatter -- -- Converts CamelCase to camel-case. -- -- see also: derivePathInfo and derivePathInfo' standard :: String -> String mkRoute :: Name -> Q [Dec]