Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- genProduct :: (Generic a, GenProduct (Rep a)) => a -> NMap (GProduct (Rep a))
- specProduct :: (Generic a, GenProduct (Rep a)) => NMap (GProduct (Rep a)) -> a
- genSum :: (Generic a, GenSum (Rep a)) => a -> NSum (GSum (Rep a))
- specSum :: (Generic a, GenSum (Rep a)) => NSum (GSum (Rep a)) -> a
- class GenProduct (f :: * -> *) where
- class GenSum (f :: * -> *) where
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 NMap
s. 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 #
genProduct', specProduct'
Instances
(SingI (GProduct f), SingI (GProduct g), GenProduct f, GenProduct g) => GenProduct (f :*: g) Source # | |
GenProduct f => GenProduct (D1 _a f) Source # | |
GenProductN f => GenProduct (C1 (MetaCons _a _b False) f) Source # | |
GenProduct f => GenProduct (C1 (MetaCons _a _b True) f) Source # | |
GenProduct (S1 (MetaSel (Just n) _a _b _c) (Rec0 t)) Source # | |
Defined in Data.NamedSOP.Generic |
class GenSum (f :: * -> *) Source #
genSum', specSum'