generics-eot-0.2.1.1: A library for generic programming that aims to be easy to understand

Safe HaskellNone
LanguageHaskell2010

Generics.Eot.Tutorial

Synopsis

Documentation

data A #

Constructors

A1 

Fields

A2 

Fields

Instances

Show A # 

Methods

showsPrec :: Int -> A -> ShowS #

show :: A -> String #

showList :: [A] -> ShowS #

Generic A # 

Associated Types

type Rep A :: * -> * #

Methods

from :: A -> Rep A x #

to :: Rep A x -> A #

type Rep A # 
>>> namesOfFields (Proxy :: Proxy A)
["foo","bar","baz"]

data B #

Constructors

B1 Int 
B2 String Bool 
B3 

Instances

Generic B # 

Associated Types

type Rep B :: * -> * #

Methods

from :: B -> Rep B x #

to :: Rep B x -> B #

type Rep B # 
>>> :kind! Eot B
Eot B :: *
= Either (Int, ()) (Either ([Char], (Bool, ())) (Either () Void))

class EotSerialize eot where #

Minimal complete definition

eotSerialize

Methods

eotSerialize :: Int -> eot -> [Int] #

Instances

EotSerialize () # 

Methods

eotSerialize :: Int -> () -> [Int] #

EotSerialize Void # 

Methods

eotSerialize :: Int -> Void -> [Int] #

(EotSerialize this, EotSerialize next) => EotSerialize (Either this next) # 

Methods

eotSerialize :: Int -> Either this next -> [Int] #

(Serialize x, EotSerialize xs) => EotSerialize (x, xs) # 

Methods

eotSerialize :: Int -> (x, xs) -> [Int] #

class Serialize a where #

Methods

serialize :: a -> [Int] #

serialize :: (HasEot a, EotSerialize (Eot a)) => a -> [Int] #

Instances

Serialize Bool # 

Methods

serialize :: Bool -> [Int] #

Serialize Int # 

Methods

serialize :: Int -> [Int] #

Serialize () # 

Methods

serialize :: () -> [Int] #

Serialize String # 

Methods

serialize :: String -> [Int] #

Serialize C # 

Methods

serialize :: C -> [Int] #

>>> genericSerialize (A1 "foo" 42)
[0,3,102,111,111,1,42]
>>> genericSerialize (A2 23 True)
[1,1,23,1,1]

class EotDeserialize eot where #

Minimal complete definition

eotDeserialize

Methods

eotDeserialize :: [Int] -> eot #

Instances

EotDeserialize () # 

Methods

eotDeserialize :: [Int] -> () #

EotDeserialize Void # 

Methods

eotDeserialize :: [Int] -> Void #

(EotDeserialize this, EotDeserialize next) => EotDeserialize (Either this next) # 

Methods

eotDeserialize :: [Int] -> Either this next #

(Deserialize x, EotDeserialize xs) => EotDeserialize (x, xs) # 

Methods

eotDeserialize :: [Int] -> (x, xs) #

class Deserialize a where #

Minimal complete definition

deserialize

Methods

deserialize :: [Int] -> a #

Instances

Deserialize Bool # 

Methods

deserialize :: [Int] -> Bool #

Deserialize Int # 

Methods

deserialize :: [Int] -> Int #

Deserialize () # 

Methods

deserialize :: [Int] -> () #

Deserialize String # 

Methods

deserialize :: [Int] -> String #

>>> genericDeserialize [0,3,102,111,111,1,42] :: A
A1 {foo = "foo", bar = 42}
>>> genericDeserialize [1,1,23,1,1] :: A
A2 {bar = 23, baz = True}
>>> (genericDeserialize $ genericSerialize $ A1 "foo" 42) :: A
A1 {foo = "foo", bar = 42}

data Person #

Constructors

Person 

Fields

Instances

Generic Person # 

Associated Types

type Rep Person :: * -> * #

Methods

from :: Person -> Rep Person x #

to :: Rep Person x -> Person #

type Rep Person # 
type Rep Person = D1 (MetaData "Person" "Generics.Eot.Tutorial" "generics-eot-0.2.1.1-1jzBRIAvUT2FVppTwlwGRI" False) (C1 (MetaCons "Person" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "name") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) (S1 (MetaSel (Just Symbol "age") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))))
>>> putStrLn $ createTableStatement (Proxy :: Proxy Person)
CREATE TABLE Person COLUMNS (name [Char], age Int);
>>> putStrLn $ createTableStatement (Proxy :: Proxy A)

...
    • No instance for (EotCreateTableStatement
                         Datatype
                         (Either ([Char], (Int, ())) (Either (Int, (Bool, ())) Void)))
        arising from a use of ‘createTableStatement’
...

data NoSelectors #

Constructors

NotSupported Int Bool 

Instances

Generic NoSelectors # 

Associated Types

type Rep NoSelectors :: * -> * #

type Rep NoSelectors # 
type Rep NoSelectors = D1 (MetaData "NoSelectors" "Generics.Eot.Tutorial" "generics-eot-0.2.1.1-1jzBRIAvUT2FVppTwlwGRI" False) (C1 (MetaCons "NotSupported" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool))))
>>> putStrLn $ createTableStatement (Proxy :: Proxy NoSelectors)
*** Exception: constructor NotSupported has no selectors, this is not supported
...

class ToString a where #

Minimal complete definition

toString

Methods

toString :: a -> String #

class ToString2 a where #

Methods

toString2 :: a -> String #

toString2 :: Show a => a -> String #

Instances

>>> toString2 (42 :: Int)
"42"

data C #

Constructors

C1 Int String 

Instances

Generic C # 

Associated Types

type Rep C :: * -> * #

Methods

from :: C -> Rep C x #

to :: Rep C x -> C #

Serialize C # 

Methods

serialize :: C -> [Int] #

type Rep C # 
type Rep C = D1 (MetaData "C" "Generics.Eot.Tutorial" "generics-eot-0.2.1.1-1jzBRIAvUT2FVppTwlwGRI" False) (C1 (MetaCons "C1" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String))))
>>> serialize (C1 42 "yay!")
[0,1,42,4,121,97,121,33]