Popularity
1.2
Declining
Activity
0.0
Stable
2
1
0

Monthly Downloads: 6
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Data    

extend-record-data-th alternatives and similar packages

Based on the "Data" category.
Alternatively, view extend-record-data-th alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of extend-record-data-th or a related project?

Add another 'Data' Package

README

data-extend-th

Hackage

TH to define a new record data type that extends the existing simple record data type.

This library should be useful when used with generic-lens.

Syntax

$(extendD "data T = T1 <> T2 <> { f1 :: T3, f2 :: T4 } deriving (c1, c2) ")

Examples

unioning existing record data type

data Animal = Animal
  { name :: String
  , age  :: Int
  } deriving (Show, Eq, Generic)

data HumanInfo = HumanInfo
  { address :: String
  } deriving (Show, Eq, Generic)

$(extendD "data Human = Animal <> HumanInfo deriving (Show, Generic) ")

data Human

:i Human
data Human
  = Human {name :: String,
           age :: Int,
           address :: String}
instance Show Human
instance Generic Human

higher kind, define field records anonymously

data X a = X {f1 :: a Int} deriving (Generic)
data Y a = Y {f2 :: Maybe a} deriving (Generic, Show)
data Z a = Z { x :: X a } deriving(Generic)
$(extendD "data XY = X <> Y <> { e1 :: String, e2 :: String } <> Z deriving (Generic)")

XY

data XY (a :: * -> *) a1 (a2 :: * -> *)
  = XY {f1 :: a Int,
        f2 :: Maybe a1,
        e1 :: String,
        e2 :: String,
        x :: X a2}
instance Generic (XY a1 a2 a3)