-- 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 -- --
-- >>> 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