eventful-core-0.1.1: Core module for eventful

Safe HaskellNone
LanguageHaskell2010

Eventful.TH.SumType

Synopsis

Documentation

mkSumType :: String -> (String -> String) -> [Name] -> Q [Dec] Source #

This is a template haskell function that creates a sum type from a list of types. This is very useful when creating an event type for a Projection from a list of events in your system. Here is an example:

   data EventA = EventA
   data EventB = EventB
   data EventC = EventC

   mkSumType MyEvent (MyEvent ++) [''EventA, ''EventB, ''EventC]

This will produce the following sum type:

   data MyEvent
     = MyEventEventA EventA
     | MyEventEventB EventB
     | MyEventEventC EventC

Note that you can use standalone deriving to derive any instances you want:

   deriving instance Show MyEvent
   deriving instance Eq MyEvent

mkSumType' :: String -> [Name] -> Q [Dec] Source #

Variant of mkSumType that just appends a ' to each constructor.

   mkSumType' name events = mkSumType name (++ "'") events