derive-topdown-0.0.0.2: This library will help you generate Haskell empty Generic instances and deriving type instances from the top automatically to the bottom for composited data types.

Safe HaskellNone
LanguageHaskell2010

Data.Derive.TopDown.Generic

Description

An example to generate Out class for Person, Name and Address. Out class has to provide a default implementation for the function it declears.

data Person = Person Names Address 
            | Student Names Address 
              deriving (Show, Generic, Eq, Ord , Data,Typeable)
data Names  = Names String 
              deriving (Show, Generic, Eq, Ord, Data, Typeable)
data Address = Address Gate
              deriving (Show, Generic, Eq, Ord, Typeable, Data)

type Gate = PF

data PF = PF String deriving (Data, Typeable, Generic, Ord,Eq,Show)

For generating 4 empty instances

instance Out Person
instnace Out Nmads
instance Out Address
instance Out Gate

you just write:

instances ''Out ''Person

It will generate all instances that form Person and including Person.

If you use :set -ddump-splices, you will get

 instances ''Out  ''Person
 ======>
 ~\Test.hs:13:1-18
   instance Out Names
   instance Out Gate
   instance Out Address
   instance Out Person
Ok, modules loaded: CompositeDataInstancesGen, Main.

You can also use instnaceList to generate a list of class.

Synopsis

Documentation

(-->) :: Name -> Name -> Q [Dec] Source

instances :: Name -> Name -> Q [Dec] Source

Synatx sugar

instanceList :: Name -> [Name] -> Q [Dec] Source

Generate instances for a list of classes with default implementation