named-sop-0.1.0.0: Dependently-typed sums and products, tagged by field name

Safe HaskellNone
LanguageHaskell2010

Data.NamedSOP.Generic

Description

 
Synopsis

Documentation

genProduct :: (Generic a, GenProduct (Rep a)) => a -> NMap (GProduct (Rep a)) Source #

Convert a single-constructor type with a Generic instance into a sorted NMap. Constructors with record selectors will use their names, and constructors without will use numbers, prefixed with _ for better compatibility with -XOverloadedLabels.

>>> data A = C { a :: Int, b :: Bool } deriving (Generic)
>>> genProduct (C { a = 1, b = True })
{ a :-> 1, b :-> True }
>>> data B = D Int Bool deriving (Generic)
>>> genProduct (D 1 True)
{ _1 :-> 1, _2 :-> True }

specProduct :: (Generic a, GenProduct (Rep a)) => NMap (GProduct (Rep a)) -> a Source #

Reverse the operation performed by genProduct.

genSum :: (Generic a, GenSum (Rep a)) => a -> NSum (GSum (Rep a)) Source #

Convert a type with a generic instance with any number of constructors into an NSum of NMaps. All constructor names will be prefixed with _ to allow for the use of -XOverloadedLabels.

>>> data A = C { a :: Int, b :: Bool } | D Int Bool deriving (Generic)
>>> :t genSum (C 3 True)
NSum
 '[ "_C" ':-> NMap '[ "a" ':-> Int, "b" ':-> Bool],
    "_D" ':-> NMap '[ "_1" ':-> Int, "_2" ':-> Bool]]

specSum :: (Generic a, GenSum (Rep a)) => NSum (GSum (Rep a)) -> a Source #

Reverse the operation performed by genSum.

class GenProduct (f :: * -> *) Source #

Minimal complete definition

genProduct', specProduct'

Associated Types

type GProduct f :: [Mapping Symbol Type] Source #

Instances
(SingI (GProduct f), SingI (GProduct g), GenProduct f, GenProduct g) => GenProduct (f :*: g) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GProduct (f :*: g) :: [Mapping Symbol Type] Source #

Methods

genProduct' :: (f :*: g) a -> NMap (GProduct (f :*: g))

specProduct' :: NMap (GProduct (f :*: g)) -> (f :*: g) a

GenProduct f => GenProduct (D1 _a f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GProduct (D1 _a f) :: [Mapping Symbol Type] Source #

Methods

genProduct' :: D1 _a f a -> NMap (GProduct (D1 _a f))

specProduct' :: NMap (GProduct (D1 _a f)) -> D1 _a f a

GenProductN f => GenProduct (C1 (MetaCons _a _b False) f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GProduct (C1 (MetaCons _a _b False) f) :: [Mapping Symbol Type] Source #

Methods

genProduct' :: C1 (MetaCons _a _b False) f a -> NMap (GProduct (C1 (MetaCons _a _b False) f))

specProduct' :: NMap (GProduct (C1 (MetaCons _a _b False) f)) -> C1 (MetaCons _a _b False) f a

GenProduct f => GenProduct (C1 (MetaCons _a _b True) f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GProduct (C1 (MetaCons _a _b True) f) :: [Mapping Symbol Type] Source #

Methods

genProduct' :: C1 (MetaCons _a _b True) f a -> NMap (GProduct (C1 (MetaCons _a _b True) f))

specProduct' :: NMap (GProduct (C1 (MetaCons _a _b True) f)) -> C1 (MetaCons _a _b True) f a

GenProduct (S1 (MetaSel (Just n) _a _b _c) (Rec0 t)) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GProduct (S1 (MetaSel (Just n) _a _b _c) (Rec0 t)) :: [Mapping Symbol Type] Source #

Methods

genProduct' :: S1 (MetaSel (Just n) _a _b _c) (Rec0 t) a -> NMap (GProduct (S1 (MetaSel (Just n) _a _b _c) (Rec0 t)))

specProduct' :: NMap (GProduct (S1 (MetaSel (Just n) _a _b _c) (Rec0 t))) -> S1 (MetaSel (Just n) _a _b _c) (Rec0 t) a

class GenSum (f :: * -> *) Source #

Minimal complete definition

genSum', specSum'

Associated Types

type GSum f :: [Mapping Symbol Type] Source #

Instances
(SingI (GSum f), SingI (GSum g), GenSum f, GenSum g) => GenSum (f :+: g) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GSum (f :+: g) :: [Mapping Symbol Type] Source #

Methods

genSum' :: (f :+: g) a -> NSum (GSum (f :+: g))

specSum' :: NSum (GSum (f :+: g)) -> (f :+: g) a

GenSum f => GenSum (D1 _a f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GSum (D1 _a f) :: [Mapping Symbol Type] Source #

Methods

genSum' :: D1 _a f a -> NSum (GSum (D1 _a f))

specSum' :: NSum (GSum (D1 _a f)) -> D1 _a f a

GenProductN f => GenSum (C1 (MetaCons n _a False) f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GSum (C1 (MetaCons n _a False) f) :: [Mapping Symbol Type] Source #

Methods

genSum' :: C1 (MetaCons n _a False) f a -> NSum (GSum (C1 (MetaCons n _a False) f))

specSum' :: NSum (GSum (C1 (MetaCons n _a False) f)) -> C1 (MetaCons n _a False) f a

GenProduct f => GenSum (C1 (MetaCons n _a True) f) Source # 
Instance details

Defined in Data.NamedSOP.Generic

Associated Types

type GSum (C1 (MetaCons n _a True) f) :: [Mapping Symbol Type] Source #

Methods

genSum' :: C1 (MetaCons n _a True) f a -> NSum (GSum (C1 (MetaCons n _a True) f))

specSum' :: NSum (GSum (C1 (MetaCons n _a True) f)) -> C1 (MetaCons n _a True) f a