-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for generic programming that aims to be easy to understand -- -- A library for generic programming that aims to be easy to understand @package generics-eot @version 0.1 -- | generics-eot tries to be a library for datatype generic -- programming that is easy to understand. "eot" stands for "eithers of -- tuples". -- -- A tutorial on how to use generics-eot can be found here: -- Generics.Eot.Tutorial. module Generics.Eot -- | An instance (HasEot a) allows us to -- -- -- -- Once an algebraic datatype has an instance for Generic it -- automatically gets one for HasEot. class HasEot a where type family Eot a :: * -- | Convert a value of type a to its generic representation. toEot :: HasEot a => a -> Eot a -- | Convert a value in a generic representation to a (inverse of -- toEot). fromEot :: HasEot a => Eot a -> a -- | Extract meta information about the ADT. datatype :: HasEot a => Proxy a -> Datatype -- | Type for meta information about ADTs. data Datatype Datatype :: String -> [Constructor] -> Datatype -- | unqualified name of the type [datatypeName] :: Datatype -> String [constructors] :: Datatype -> [Constructor] data Constructor Constructor :: String -> Fields -> Constructor [constructorName] :: Constructor -> String [fields] :: Constructor -> Fields -- | Type that represents meta information about fields of one constructor. data Fields -- | Record constructor, containing the list of the selector names. Selectors :: [String] -> Fields -- | Constructor with fields, but without selector names. The argument -- gives the number of fields. NoSelectors :: Int -> Fields -- | Constructor without fields. NoFields :: Fields -- | Uninhabited type. data Void -- | Representable types of kind *. This class is derivable in GHC with the -- DeriveGeneric flag on. class Generic a -- | A concrete, poly-kinded proxy type data Proxy (t :: k) :: k -> * Proxy :: Proxy instance (GHC.Generics.Generic a, Generics.Eot.ImpliedByGeneric a c f) => Generics.Eot.HasEot a -- | This tutorial is meant to be read alongside with the haddock comments -- in Generics.Eot. -- -- generics-eot allows roughly three different kinds of -- operations: -- --
    --
  1. Accessing meta information about ADTs (datatype for names, -- Proxy and Eot for field types). Example: Generation of -- database schemas for ADTs.
  2. --
  3. Deconstructing values generically (toEot). Example: -- Serialization to a binary format.
  4. --
  5. Constructing values of an ADT generically (fromEot). -- Example: Deserialization from a binary format.
  6. --
-- -- Sometimes only one of the three forms is used but often multiple have -- to be combined. For example serialization to JSON usually requires -- both datatype and toEot. module Generics.Eot.Tutorial -- | This simple function extracts the names of all field selectors and -- returns them as a list: -- --
--   >>> namesOfFields (Proxy :: Proxy A)
--   ["foo","bar","baz"]
--   
-- -- (You're encouraged to look at the source code of the examples in this -- tutorial to understand how they work. If you're looking at a web page -- generated by haddock, you'll hopefully find Source links to -- the right.) namesOfFields :: HasEot a => Proxy a -> [String] data A A1 :: String -> Int -> A [foo] :: A -> String [bar] :: A -> Int A2 :: Int -> Bool -> A [bar] :: A -> Int [baz] :: A -> Bool data B B1 :: Int -> B B2 :: String -> Bool -> B B3 :: B class EotSerialize eot eotSerialize :: EotSerialize eot => Int -> eot -> [Int] -- | This is the class Serialize. It's used to serialize every field -- of the used ADTs, so we need instances for all of them. class Serialize a where serialize = genericSerialize serialize :: Serialize a => a -> [Int] -- | To tie everything together we provide a function -- genericSerialize that converts a value of some ADT into an eot -- value using toEot and then uses eotSerialize to convert -- that eot value into a list of Ints. genericSerialize :: (HasEot a, EotSerialize (Eot a)) => a -> [Int] class EotDeserialize eot eotDeserialize :: EotDeserialize eot => [Int] -> eot class Deserialize a deserialize :: Deserialize a => [Int] -> a -- | And here's genericDeserialize to tie it together. It uses -- eotDeserialize to convert a list of Ints into an eot -- value and then fromEot to construct a value of the wanted ADT. genericDeserialize :: (HasEot a, EotDeserialize (Eot a)) => [Int] -> a class EotCreateTableStatement meta eot eotCreateTableStatement :: EotCreateTableStatement meta eot => meta -> Proxy eot -> [String] -- | createTableStatement ties everything together. It obtaines the -- meta information through datatype passing a Proxy for -- a. And it creates a Proxy for the eot-type: -- --
--   Proxy :: Proxy (Eot a)
--   
-- -- Then it calls eotCreateTableStatement and just concats -- the resulting snippets. createTableStatement :: (HasEot a, EotCreateTableStatement Datatype (Eot a)) => Proxy a -> String data Person Person :: String -> Int -> Person [name] :: Person -> String [age] :: Person -> Int data NoSelectors NotSupported :: Int -> Bool -> NoSelectors class ToString a where toString = show toString :: ToString a => a -> String data C C1 :: Int -> String -> C instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_0C instance GHC.Generics.Datatype Generics.Eot.Tutorial.D1C instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_0NoSelectors instance GHC.Generics.Datatype Generics.Eot.Tutorial.D1NoSelectors instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_0_1Person instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_0_0Person instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_0Person instance GHC.Generics.Datatype Generics.Eot.Tutorial.D1Person instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_2B instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_1B instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_0B instance GHC.Generics.Datatype Generics.Eot.Tutorial.D1B instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_1_1A instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_1_0A instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_0_1A instance GHC.Generics.Selector Generics.Eot.Tutorial.S1_0_0A instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_1A instance GHC.Generics.Constructor Generics.Eot.Tutorial.C1_0A instance GHC.Generics.Datatype Generics.Eot.Tutorial.D1A instance GHC.Generics.Generic Generics.Eot.Tutorial.C instance GHC.Generics.Generic Generics.Eot.Tutorial.NoSelectors instance GHC.Generics.Generic Generics.Eot.Tutorial.Person instance GHC.Generics.Generic Generics.Eot.Tutorial.B instance GHC.Show.Show Generics.Eot.Tutorial.A instance GHC.Generics.Generic Generics.Eot.Tutorial.A instance (Generics.Eot.Tutorial.EotSerialize this, Generics.Eot.Tutorial.EotSerialize next) => Generics.Eot.Tutorial.EotSerialize (Data.Either.Either this next) instance Generics.Eot.Tutorial.EotSerialize Generics.Eot.Eot.Void instance (Generics.Eot.Tutorial.Serialize x, Generics.Eot.Tutorial.EotSerialize xs) => Generics.Eot.Tutorial.EotSerialize (x, xs) instance Generics.Eot.Tutorial.EotSerialize () instance Generics.Eot.Tutorial.Serialize GHC.Types.Int instance Generics.Eot.Tutorial.Serialize GHC.Base.String instance Generics.Eot.Tutorial.Serialize GHC.Types.Bool instance Generics.Eot.Tutorial.Serialize () instance (Generics.Eot.Tutorial.EotDeserialize this, Generics.Eot.Tutorial.EotDeserialize next) => Generics.Eot.Tutorial.EotDeserialize (Data.Either.Either this next) instance Generics.Eot.Tutorial.EotDeserialize Generics.Eot.Eot.Void instance (Generics.Eot.Tutorial.Deserialize x, Generics.Eot.Tutorial.EotDeserialize xs) => Generics.Eot.Tutorial.EotDeserialize (x, xs) instance Generics.Eot.Tutorial.EotDeserialize () instance Generics.Eot.Tutorial.Deserialize GHC.Types.Int instance Generics.Eot.Tutorial.Deserialize GHC.Base.String instance Generics.Eot.Tutorial.Deserialize () instance Generics.Eot.Tutorial.Deserialize GHC.Types.Bool instance Generics.Eot.Tutorial.EotCreateTableStatement [GHC.Base.String] fields => Generics.Eot.Tutorial.EotCreateTableStatement Generics.Eot.Datatype.Datatype (Data.Either.Either fields Generics.Eot.Eot.Void) instance (Data.Typeable.Internal.Typeable x, Generics.Eot.Tutorial.EotCreateTableStatement [GHC.Base.String] xs) => Generics.Eot.Tutorial.EotCreateTableStatement [GHC.Base.String] (x, xs) instance Generics.Eot.Tutorial.EotCreateTableStatement [GHC.Base.String] () instance Generics.Eot.Tutorial.ToString GHC.Types.Int instance Generics.Eot.Tutorial.Serialize Generics.Eot.Tutorial.C