-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Derive a model of a data type using Generics -- -- See the online tutorial @package model @version 0.2.4 -- | Nats with * kind module Type.ANat -- | Envelope to get Nats with * kind data ANat (n :: Nat) -- | Convert a Nat to the corresponding Integer -- --
--   >>> anatVal (undefined::A5)
--   5
--   
anatVal :: KnownNat n => ANat n -> Integer type A0 = ANat 0 type A1 = ANat 1 type A2 = ANat 2 type A3 = ANat 3 type A4 = ANat 4 type A5 = ANat 5 type A6 = ANat 6 type A7 = ANat 7 type A8 = ANat 8 type A9 = ANat 9 -- | Utility to abstract parametric types module Type.Analyse -- | Abstract a concrete type to a type applied to variables. -- -- More precisely: to a meta-representation where type application is -- represented by App, data types are marked by Typ and -- variables are represented by ANat types. -- -- BUG: Silently fails for types with more than 9 parameters (should be -- defined recursively, if you know how let me know) -- -- Examples: -- --
--   >>> undefined :: Ana (Maybe Char)
--   undefined :: Ana (Maybe Char) :: App (Typ (Maybe A0)) (Typ Char)
--   
-- --
--   >>> undefined :: Ana (Either Int Char)
--   undefined :: Ana (Either Int Char)
--     :: App (App (Typ (Either A0 A1)) (Typ Int)) (Typ Char)
--   
-- --
--   >>> undefined :: Ana ([(Bool,())])
--   undefined :: Ana ([(Bool,())])
--     :: App (Typ [A0]) (App (App (Typ (A0, A1)) (Typ Bool)) (Typ ()))
--   
-- | Type application data App f a -- | A data type data Typ a module Data.Model.Util -- | Return the groups of entities that are mutually dependent -- --
--   >>> mutualGroups Just (M.fromList [("a",["b","c"]),("b",["a","c"]),("c",[])])
--   [["c"],["a","b"]]
--   
mutualGroups :: (Ord r, Show r, Foldable t) => (a -> Maybe r) -> Map r (t a) -> [[r]] -- | Return a list of the unique recursive dependencies of n in env -- excluding n, even if self-recursive -- --
--   >>> dependencies Just (M.fromList [("a",["b","c"]),("b",["b","d","d","c"]),("c",[]),("d",["a"])]) "a"
--   Right ["b","d","c"]
--   
-- --
--   >>> dependencies Just (M.fromList [("a",["b","c"]),("b",["b","d","d","c"]),("c",[]),("d",["a"])]) "b"
--   Right ["d","a","c"]
--   
dependencies :: (Ord r, Show r, Foldable t) => (a -> Maybe r) -> Map r (t a) -> r -> Either Errors [r] type Errors = [String] instance GHC.Show.Show r => GHC.Show.Show (Data.Model.Util.RecState r) -- | A model for simple algebraic data types. module Data.Model.Types -- | The complete model of a type, a reference to the type plus its -- environment: -- -- data TypeModel adtName consName inRef exRef TypeModel :: Type exRef -> TypeEnv adtName consName inRef exRef -> TypeModel adtName consName inRef exRef -- | The type application corresponding to the type [typeName] :: TypeModel adtName consName inRef exRef -> Type exRef -- | The environment in which the type is defined [typeEnv] :: TypeModel adtName consName inRef exRef -> TypeEnv adtName consName inRef exRef -- | A map of all the ADTs that are directly or indirectly referred by a -- type, indexed by a type reference type TypeEnv adtName consName inRef exRef = Map exRef (ADT adtName consName inRef) -- | The ADTs defined in the TypeModel typeADTs :: TypeModel adtName consName inRef k -> [ADT adtName consName inRef] -- | Simple algebraic data type (not a GADT): -- -- data ADT name consName ref ADT :: name -> Word8 -> Maybe (ConTree consName ref) -> ADT name consName ref -- | The name of the data type (for example Bool for data -- Bool) [declName] :: ADT name consName ref -> name -- | The number of type parameters/variable (up to a maximum of 255) [declNumParameters] :: ADT name consName ref -> Word8 -- | The constructors, if present [declCons] :: ADT name consName ref -> Maybe (ConTree consName ref) -- | Constructors are assembled in a binary tree data ConTree name ref Con :: name -> Either [Type ref] [(name, Type ref)] -> ConTree name ref -- | The constructor name, unique in the data type [constrName] :: ConTree name ref -> name -- | Constructor fields, they can be either unnamed (Left case) or named -- (Right case) If they are named, they must all be named [constrFields] :: ConTree name ref -> Either [Type ref] [(name, Type ref)] -- | Constructor tree. -- -- Constructors are disposed in an optimally balanced, right heavier -- tree: -- -- For example, the data type: -- --
--   data N = One | Two | Three | Four | Five
--   
-- -- Would have its contructors ordered in the following tree: -- --
--           |
--      |            |
--   One Two   Three   |
--                 Four Five
--   
-- -- To get a list of constructor in declaration order, use -- constructors ConTree :: (ConTree name ref) -> (ConTree name ref) -> ConTree name ref -- | A type data Type ref -- | Type constructor (Bool,Maybe,..) TypeCon :: ref -> Type ref -- | Type application TypeApp :: (Type ref) -> (Type ref) -> Type ref -- | Another representation of a type, sometime easier to work with data TypeN r TypeN :: r -> [TypeN r] -> TypeN r -- | A reference to a type data TypeRef name -- | Type variable TypVar :: Word8 -> TypeRef name -- | Type reference TypRef :: name -> TypeRef name -- | Simple name data Name Name :: String -> Name -- | A fully qualified Haskell name data QualName QualName :: String -> QualName [pkgName, mdlName, locName] :: QualName -> String -- | Return the qualified name, minus the package name. qualName :: QualName -> String -- | Map over the names of an ADT and of its constructors adtNamesMap :: (adtName1 -> adtName2) -> (consName1 -> consName2) -> ADT adtName1 consName1 ref -> ADT adtName2 consName2 ref -- | Convert from Type to TypeN typeN :: Type r -> TypeN r -- | Convert from TypeN to Type typeA :: TypeN ref -> Type ref -- | Return the list of constructors in definition order constructors :: ConTree t t1 -> [ConTree t t1] -- | Return the binary encoding and parameter types of a constructor The -- binary encoding is the sequence of Left (False) and Right (True) turns -- needed to reach the constructor from the constructor tree root. -- constructorInfo :: Eq consName => consName -> ADT name consName -- ref -> Maybe ([Bool], [Type ref]) constructorInfo consName dt = -- declCons dt >>= ((first reverse $) . loc []) constructorInfo :: Eq consName => consName -> ConTree consName t -> Maybe ([Bool], [Type t]) -- | Map over a constructor tree names conTreeNameMap :: (name -> name2) -> ConTree name t -> ConTree name2 t -- | Map on the constructor types (used for example when eliminating -- variables) conTreeTypeMap :: (Type t -> Type ref) -> ConTree name t -> ConTree name ref -- | Extract list of types in a constructor tree conTreeTypeList :: ConTree name t -> [Type t] -- | Fold over the types in a constructor tree conTreeTypeFoldMap :: Monoid a => (Type t -> a) -> ConTree name t -> a -- | Return just the field types fieldsTypes :: Either [b] [(a, b)] -> [b] -- | Return just the field names (or an empty list if unspecified) fieldsNames :: Either t [(a, t1)] -> [t1] -- | Haskell Environment type HTypeEnv = TypeEnv String String (TypeRef QualName) QualName -- | Haskell TypeModel type HTypeModel = TypeModel String String (TypeRef QualName) QualName -- | Haskell ADT type HADT = ADT String String HTypeRef -- | Haskell Type type HType = Type HTypeRef -- | Reference to an Haskell Type type HTypeRef = TypeRef QualName -- | Solve a key in an environment, returns an error if the key is missing solve :: (Ord k, Show k) => k -> Map k a -> a -- | Solve all references in a data structure, using the given environment solveAll :: (Functor f, Show k, Ord k) => Map k b -> f k -> f b -- | Remove variable references (for example if we know that a type is -- fully saturated and cannot contain variables) unVar :: TypeRef t -> t -- | Extract reference getHRef :: TypeRef a -> Maybe a -- | A concrete, poly-kinded proxy type data Proxy k (t :: k) :: forall k. k -> * Proxy :: Proxy k instance GHC.Generics.Generic Data.Model.Types.Name instance Control.DeepSeq.NFData Data.Model.Types.Name instance GHC.Show.Show Data.Model.Types.Name instance GHC.Classes.Ord Data.Model.Types.Name instance GHC.Classes.Eq Data.Model.Types.Name instance GHC.Generics.Generic Data.Model.Types.QualName instance Control.DeepSeq.NFData Data.Model.Types.QualName instance GHC.Show.Show Data.Model.Types.QualName instance GHC.Classes.Ord Data.Model.Types.QualName instance GHC.Classes.Eq Data.Model.Types.QualName instance Data.Traversable.Traversable Data.Model.Types.TypeRef instance Data.Foldable.Foldable Data.Model.Types.TypeRef instance GHC.Base.Functor Data.Model.Types.TypeRef instance GHC.Generics.Generic (Data.Model.Types.TypeRef name) instance Control.DeepSeq.NFData name => Control.DeepSeq.NFData (Data.Model.Types.TypeRef name) instance GHC.Show.Show name => GHC.Show.Show (Data.Model.Types.TypeRef name) instance GHC.Classes.Ord name => GHC.Classes.Ord (Data.Model.Types.TypeRef name) instance GHC.Classes.Eq name => GHC.Classes.Eq (Data.Model.Types.TypeRef name) instance Data.Traversable.Traversable Data.Model.Types.TypeN instance Data.Foldable.Foldable Data.Model.Types.TypeN instance GHC.Base.Functor Data.Model.Types.TypeN instance GHC.Generics.Generic (Data.Model.Types.TypeN r) instance Control.DeepSeq.NFData r => Control.DeepSeq.NFData (Data.Model.Types.TypeN r) instance GHC.Show.Show r => GHC.Show.Show (Data.Model.Types.TypeN r) instance GHC.Read.Read r => GHC.Read.Read (Data.Model.Types.TypeN r) instance GHC.Classes.Ord r => GHC.Classes.Ord (Data.Model.Types.TypeN r) instance GHC.Classes.Eq r => GHC.Classes.Eq (Data.Model.Types.TypeN r) instance GHC.Generics.Generic (Data.Model.Types.TypeModel adtName consName inRef exRef) instance (Control.DeepSeq.NFData adtName, Control.DeepSeq.NFData inRef, Control.DeepSeq.NFData consName, Control.DeepSeq.NFData exRef) => Control.DeepSeq.NFData (Data.Model.Types.TypeModel adtName consName inRef exRef) instance (GHC.Show.Show adtName, GHC.Show.Show inRef, GHC.Show.Show consName, GHC.Show.Show exRef) => GHC.Show.Show (Data.Model.Types.TypeModel adtName consName inRef exRef) instance (GHC.Classes.Ord adtName, GHC.Classes.Ord inRef, GHC.Classes.Ord consName, GHC.Classes.Ord exRef) => GHC.Classes.Ord (Data.Model.Types.TypeModel adtName consName inRef exRef) instance (GHC.Classes.Eq adtName, GHC.Classes.Eq inRef, GHC.Classes.Eq consName, GHC.Classes.Eq exRef) => GHC.Classes.Eq (Data.Model.Types.TypeModel adtName consName inRef exRef) instance Data.Traversable.Traversable (Data.Model.Types.ADT name consName) instance Data.Foldable.Foldable (Data.Model.Types.ADT name consName) instance GHC.Base.Functor (Data.Model.Types.ADT name consName) instance GHC.Generics.Generic (Data.Model.Types.ADT name consName ref) instance (Control.DeepSeq.NFData consName, Control.DeepSeq.NFData ref, Control.DeepSeq.NFData name) => Control.DeepSeq.NFData (Data.Model.Types.ADT name consName ref) instance (GHC.Show.Show consName, GHC.Show.Show ref, GHC.Show.Show name) => GHC.Show.Show (Data.Model.Types.ADT name consName ref) instance (GHC.Classes.Ord consName, GHC.Classes.Ord ref, GHC.Classes.Ord name) => GHC.Classes.Ord (Data.Model.Types.ADT name consName ref) instance (GHC.Classes.Eq consName, GHC.Classes.Eq ref, GHC.Classes.Eq name) => GHC.Classes.Eq (Data.Model.Types.ADT name consName ref) instance GHC.Generics.Generic (Data.Model.Types.ConTree name ref) instance (Control.DeepSeq.NFData ref, Control.DeepSeq.NFData name) => Control.DeepSeq.NFData (Data.Model.Types.ConTree name ref) instance (GHC.Show.Show ref, GHC.Show.Show name) => GHC.Show.Show (Data.Model.Types.ConTree name ref) instance (GHC.Classes.Ord ref, GHC.Classes.Ord name) => GHC.Classes.Ord (Data.Model.Types.ConTree name ref) instance (GHC.Classes.Eq ref, GHC.Classes.Eq name) => GHC.Classes.Eq (Data.Model.Types.ConTree name ref) instance Data.Traversable.Traversable Data.Model.Types.Type instance Data.Foldable.Foldable Data.Model.Types.Type instance GHC.Base.Functor Data.Model.Types.Type instance GHC.Generics.Generic (Data.Model.Types.Type ref) instance Control.DeepSeq.NFData ref => Control.DeepSeq.NFData (Data.Model.Types.Type ref) instance GHC.Show.Show ref => GHC.Show.Show (Data.Model.Types.Type ref) instance GHC.Classes.Ord ref => GHC.Classes.Ord (Data.Model.Types.Type ref) instance GHC.Classes.Eq ref => GHC.Classes.Eq (Data.Model.Types.Type ref) instance GHC.Base.Functor (Data.Model.Types.ConTree name) instance Data.Foldable.Foldable (Data.Model.Types.ConTree name) instance Data.Traversable.Traversable (Data.Model.Types.ConTree name) instance Data.ListLike.String.StringLike Data.Model.Types.QualName instance Data.ListLike.String.StringLike GHC.Base.String instance Data.ListLike.String.StringLike Data.Model.Types.Name -- | Pretty instances for the model types module Data.Model.Pretty -- | Intercalate with a dot dotted :: [String] -> Doc -- | Separate with a space spacedP :: Pretty a => [a] -> Doc -- | Separate with a new line vspacedP :: Pretty a => [a] -> Doc -- | Convert a variable number (0,1,..) to a name -- (a,b,..) varP :: Integral n => n -> Doc -- | Pretty printing class. The precedence level is used in a similar way -- as in the Show class. Minimal complete definition is either -- pPrintPrec or pPrint. class Pretty a pPrintPrec :: Pretty a => PrettyLevel -> Rational -> a -> Doc pPrint :: Pretty a => a -> Doc pPrintList :: Pretty a => PrettyLevel -> [a] -> Doc -- | Pretty print a value with the prettyNormal level. prettyShow :: Pretty a => a -> String instance (Text.PrettyPrint.HughesPJClass.Pretty exRef, GHC.Classes.Ord exRef, GHC.Show.Show exRef, Data.ListLike.String.StringLike adtName, Data.ListLike.String.StringLike consName, Data.ListLike.String.StringLike ref) => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.TypeModel adtName consName (Data.Model.Types.TypeRef ref) exRef) instance (Text.PrettyPrint.HughesPJClass.Pretty n, Text.PrettyPrint.HughesPJClass.Pretty cn, Text.PrettyPrint.HughesPJClass.Pretty r) => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.ADT n cn r) instance (Text.PrettyPrint.HughesPJClass.Pretty name, Text.PrettyPrint.HughesPJClass.Pretty ref) => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.ConTree name ref) instance Text.PrettyPrint.HughesPJClass.Pretty n => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.TypeRef n) instance Text.PrettyPrint.HughesPJClass.Pretty r => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.Type r) instance Text.PrettyPrint.HughesPJClass.Pretty r => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Types.TypeN r) instance Text.PrettyPrint.HughesPJClass.Pretty Data.Model.Types.QualName instance Text.PrettyPrint.HughesPJClass.Pretty Data.Model.Types.Name instance Text.PrettyPrint.HughesPJClass.Pretty Text.PrettyPrint.HughesPJ.Doc instance Text.PrettyPrint.HughesPJClass.Pretty r => Text.PrettyPrint.HughesPJClass.Pretty (Data.Model.Pretty.PrettyType r) -- | Environment used while capturing model module Data.Model.Env -- | A state monad parameterized by the type s of the state to -- carry. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. type State s = StateT s Identity -- | Environment used while capturing model data Env -- | Run the model capturing computation withEnv :: State Env HType -> HTypeModel -- | Enter a type enterCtx :: QualName -> State Env Bool -- | Add a new data type model to the environment addDef :: QualName -> HADT -> State Env () -- | Leave current type closeCtx :: State Env () instance GHC.Show.Show Data.Model.Env.Env module Data.Model.Class -- | Return the model for the given type typeModel :: AsType (Ana a) => Proxy a -> HTypeModel -- | Class of types whose model can be calculated Instances are derived -- automatically, provided that the data type has an instance for -- Generics class (Typeable a, AsType (Ana a)) => Model a where envType p = addCT_ False p $ gcons (from (undefined :: a)) -- | Given a type proxy, update the environment with the ADTs referred by -- it and return the corresponding HType envType :: Model a => Proxy a -> State Env HType -- | Given a type proxy, update the environment with the ADTs referred by -- it and return the corresponding HType envType :: (Model a, Generic a, GModel (Rep a)) => Proxy a -> State Env HType -- | Helper class used to capture the type parameters class AsType a asType :: AsType a => a -> State Env HType -- | Use the given constructors tree as model for the given type, returns -- the build type Exported so that it can be used to overwrite default -- definitions useCT :: Typeable a => Maybe (ConTree String HTypeRef) -> proxy a -> State Env (Type (TypeRef QualName)) -- | Abstract a concrete type to a type applied to variables. -- -- More precisely: to a meta-representation where type application is -- represented by App, data types are marked by Typ and -- variables are represented by ANat types. -- -- BUG: Silently fails for types with more than 9 parameters (should be -- defined recursively, if you know how let me know) -- -- Examples: -- --
--   >>> undefined :: Ana (Maybe Char)
--   undefined :: Ana (Maybe Char) :: App (Typ (Maybe A0)) (Typ Char)
--   
-- --
--   >>> undefined :: Ana (Either Int Char)
--   undefined :: Ana (Either Int Char)
--     :: App (App (Typ (Either A0 A1)) (Typ Int)) (Typ Char)
--   
-- --
--   >>> undefined :: Ana ([(Bool,())])
--   undefined :: Ana ([(Bool,())])
--     :: App (Typ [A0]) (App (App (Typ (A0, A1)) (Typ Bool)) (Typ ()))
--   
instance Data.Model.Class.Model a => Data.Model.Class.AsType (Type.Analyse.Typ a) instance (Data.Model.Class.AsType f, Data.Model.Class.AsType a) => Data.Model.Class.AsType (Type.Analyse.App f a) instance (GHC.TypeLits.KnownNat t, Data.Typeable.Internal.Typeable t) => Data.Model.Class.Model (Type.ANat.ANat t) instance Data.Model.Class.GModel (GHC.Generics.M1 GHC.Generics.D d GHC.Generics.V1) instance (Data.Model.Class.GModel a, GHC.Generics.Datatype d, GHC.Generics.Constructor c) => Data.Model.Class.GModel (GHC.Generics.M1 GHC.Generics.D d (GHC.Generics.M1 GHC.Generics.C c a)) instance (GHC.Generics.Datatype d, Data.Model.Class.GModel a, Data.Model.Class.GModel b) => Data.Model.Class.GModel (GHC.Generics.M1 GHC.Generics.D d (a GHC.Generics.:+: b)) instance (Data.Model.Class.GModel a, GHC.Generics.Constructor c) => Data.Model.Class.GModel (GHC.Generics.M1 GHC.Generics.C c a) instance (Data.Model.Class.GModel a, Data.Model.Class.GModel b) => Data.Model.Class.GModel (a GHC.Generics.:+: b) instance (GHC.Generics.Selector c, Data.Model.Class.GModel a) => Data.Model.Class.GModel (GHC.Generics.M1 GHC.Generics.S c a) instance (Data.Model.Class.GModel a, Data.Model.Class.GModel b) => Data.Model.Class.GModel (a GHC.Generics.:*: b) instance Data.Model.Class.GModel GHC.Generics.U1 instance (Data.Model.Class.AsType (Type.Analyse.Ana a), Data.Model.Class.Model a) => Data.Model.Class.GModel (GHC.Generics.K1 i a) -- | Instances of Model for common types (Bool,Maybe,Either). module Data.Model.Instances instance Data.Model.Class.Model GHC.Types.Bool instance Data.Model.Class.Model a => Data.Model.Class.Model (GHC.Base.Maybe a) instance (Data.Model.Class.Model a, Data.Model.Class.Model b) => Data.Model.Class.Model (Data.Either.Either a b) module Data.Model