@@ -36,6 +36,7 @@ module Data.Aeson.Types.ToJSON (
36 -- * Generic JSON classes
36 -- * Generic JSON classes
37 , GToJSON(..)
37 , GToJSON(..)
38 , GToEncoding(..)
38 , GToEncoding(..)
39 , genericToJSON
40 , genericToJSON
40 , genericToEncoding
41 , genericToEncoding
41 , genericLiftToJSON
42 , genericLiftToJSON
@@ -138,8 +139,7 @@ class GToJSON arity f where
138 -- | This method (applied to 'defaultOptions') is used as the
139 -- | This method (applied to 'defaultOptions') is used as the
139 -- default generic implementation of 'toJSON' (if the @arity@ is 'Zero')
140 -- default generic implementation of 'toJSON' (if the @arity@ is 'Zero')
140 -- or 'liftToJSON' (if the @arity@ is 'One').
141 -- or 'liftToJSON' (if the @arity@ is 'One').
141− gToJSON :: Options -> Proxy arity
142+ gToJSON :: Options -> ToArgs Value arity a -> f a -> Value
142− -> (a -> Value) -> ([a] -> Value) -> f a -> Value
144-- | Class of generic representation types that can be converted to
144-- | Class of generic representation types that can be converted to
145-- a JSON 'Encoding'.
145-- a JSON 'Encoding'.
@@ -147,15 +147,21 @@ class GToEncoding arity f where
147 -- | This method (applied to 'defaultOptions') can be used as the
147 -- | This method (applied to 'defaultOptions') can be used as the
148 -- default generic implementation of 'toEncoding' (if the @arity@ is 'Zero')
148 -- default generic implementation of 'toEncoding' (if the @arity@ is 'Zero')
149 -- or 'liftToEncoding' (if the @arity@ is 'One').
149 -- or 'liftToEncoding' (if the @arity@ is 'One').
150− gToEncoding :: Options -> Proxy arity
150+ gToEncoding :: Options -> ToArgs Encoding arity a -> f a -> Encoding
151− -> (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding
151+
152+-- | A 'ToArgs' value either stores nothing (for 'ToJSON') or it stores the two
153+-- function arguments that encode occurrences of the type parameter (for
155+data ToArgs res arity a where
156+ NoToArgs :: ToArgs res Zero a
157+ To1Args :: (a -> res) -> ([a] -> res) -> ToArgs res One a
153-- | A configurable generic JSON creator. This function applied to
159-- | A configurable generic JSON creator. This function applied to
154-- 'defaultOptions' is used as the default for 'toJSON' when the type
160-- 'defaultOptions' is used as the default for 'toJSON' when the type
155-- is an instance of 'Generic'.
161-- is an instance of 'Generic'.
156genericToJSON :: (Generic a, GToJSON Zero (Rep a))
162genericToJSON :: (Generic a, GToJSON Zero (Rep a))
157 => Options -> a -> Value
163 => Options -> a -> Value
158−genericToJSON opts = gToJSON opts proxyZero undefined undefined . from
164+genericToJSON opts = gToJSON opts NoToArgs . from
160-- | A configurable generic JSON creator. This function applied to
166-- | A configurable generic JSON creator. This function applied to
161-- 'defaultOptions' is used as the default for 'liftToJSON' when the type
167-- 'defaultOptions' is used as the default for 'liftToJSON' when the type
@@ -163,14 +169,14 @@ genericToJSON opts = gToJSON opts proxyZero undefined undefined . from
163genericLiftToJSON :: (Generic1 f, GToJSON One (Rep1 f))
169genericLiftToJSON :: (Generic1 f, GToJSON One (Rep1 f))
164 => Options -> (a -> Value) -> ([a] -> Value)
170 => Options -> (a -> Value) -> ([a] -> Value)
165 -> f a -> Value
171 -> f a -> Value
166−genericLiftToJSON opts tj tjl = gToJSON opts proxyOne tj tjl . from1
172+genericLiftToJSON opts tj tjl = gToJSON opts (To1Args tj tjl) . from1
168-- | A configurable generic JSON encoder. This function applied to
174-- | A configurable generic JSON encoder. This function applied to
169-- 'defaultOptions' is used as the default for 'toEncoding' when the type
175-- 'defaultOptions' is used as the default for 'toEncoding' when the type
170-- is an instance of 'Generic'.
176-- is an instance of 'Generic'.
171genericToEncoding :: (Generic a, GToEncoding Zero (Rep a))
177genericToEncoding :: (Generic a, GToEncoding Zero (Rep a))
172 => Options -> a -> Encoding
178 => Options -> a -> Encoding
173−genericToEncoding opts = gToEncoding opts proxyZero undefined undefined . from
179+genericToEncoding opts = gToEncoding opts NoToArgs . from
175-- | A configurable generic JSON encoder. This function applied to
181-- | A configurable generic JSON encoder. This function applied to
176-- 'defaultOptions' is used as the default for 'liftToEncoding' when the type
182-- 'defaultOptions' is used as the default for 'liftToEncoding' when the type
@@ -178,7 +184,7 @@ genericToEncoding opts = gToEncoding opts proxyZero undefined undefined . from
178genericLiftToEncoding :: (Generic1 f, GToEncoding One (Rep1 f))
184genericLiftToEncoding :: (Generic1 f, GToEncoding One (Rep1 f))
179 => Options -> (a -> Encoding) -> ([a] -> Encoding)
185 => Options -> (a -> Encoding) -> ([a] -> Encoding)
180 -> f a -> Encoding
186 -> f a -> Encoding
181−genericLiftToEncoding opts te tel = gToEncoding opts proxyOne te tel . from1
187+genericLiftToEncoding opts te tel = gToEncoding opts (To1Args te tel) . from1
183-------------------------------------------------------------------------------
189-------------------------------------------------------------------------------
@@ -595,30 +601,30 @@ instance (ToJSON a) => ToJSON [a] where
596instance OVERLAPPABLE_ (GToJSON arity a) => GToJSON arity (M1 i c a) where
602instance OVERLAPPABLE_ (GToJSON arity a) => GToJSON arity (M1 i c a) where
597 -- Meta-information, which is not handled elsewhere, is ignored:
603 -- Meta-information, which is not handled elsewhere, is ignored:
598− gToJSON opts pa tj tjl = gToJSON opts pa tj tjl . unM1
604+ gToJSON opts targs = gToJSON opts targs . unM1
600instance (ToJSON a) => GToJSON arity (K1 i a) where
606instance (ToJSON a) => GToJSON arity (K1 i a) where
601 -- Constant values are encoded using their ToJSON instance:
607 -- Constant values are encoded using their ToJSON instance:
602− gToJSON _opts _ _ _ = toJSON . unK1
608+ gToJSON _opts _ = toJSON . unK1
604instance GToJSON One Par1 where
610instance GToJSON One Par1 where
605 -- Direct occurrences of the last type parameter are encoded with the
611 -- Direct occurrences of the last type parameter are encoded with the
606 -- function passed in as an argument:
612 -- function passed in as an argument:
607− gToJSON _opts _ tj _ = tj . unPar1
613+ gToJSON _opts (To1Args tj _) = tj . unPar1
609instance (ToJSON1 f) => GToJSON One (Rec1 f) where
615instance (ToJSON1 f) => GToJSON One (Rec1 f) where
610 -- Recursive occurrences of the last type parameter are encoded using their
616 -- Recursive occurrences of the last type parameter are encoded using their
611 -- ToJSON1 instance:
617 -- ToJSON1 instance:
612− gToJSON _opts _ tj tjl = liftToJSON tj tjl . unRec1
618+ gToJSON _opts (To1Args tj tjl) = liftToJSON tj tjl . unRec1
614instance GToJSON arity U1 where
620instance GToJSON arity U1 where
615 -- Empty constructors are encoded to an empty array:
621 -- Empty constructors are encoded to an empty array:
616− gToJSON _opts _ _ _ _ = emptyArray
622+ gToJSON _opts _ _ = emptyArray
618instance (ConsToJSON arity a) => GToJSON arity (C1 c a) where
624instance (ConsToJSON arity a) => GToJSON arity (C1 c a) where
619 -- Constructors need to be encoded differently depending on whether they're
625 -- Constructors need to be encoded differently depending on whether they're
620 -- a record or not. This distinction is made by 'consToJSON':
626 -- a record or not. This distinction is made by 'consToJSON':
621− gToJSON opts pa tj tjl = consToJSON opts pa tj tjl . unM1
627+ gToJSON opts targs = consToJSON opts targs . unM1
623instance ( WriteProduct arity a, WriteProduct arity b
629instance ( WriteProduct arity a, WriteProduct arity b
624 , ProductSize a, ProductSize b
630 , ProductSize a, ProductSize b
@@ -626,10 +632,10 @@ instance ( WriteProduct arity a, WriteProduct arity b
626 -- Products are encoded to an array. Here we allocate a mutable vector of
632 -- Products are encoded to an array. Here we allocate a mutable vector of
627 -- the same size as the product and write the product's elements to it using
633 -- the same size as the product and write the product's elements to it using
628 -- 'writeProduct':
634 -- 'writeProduct':
629− gToJSON opts pa tj tjl p =
635+ gToJSON opts targs p =
630 Array $ V.create $ do
636 Array $ V.create $ do
631 mv <- VM.unsafeNew lenProduct
637 mv <- VM.unsafeNew lenProduct
632− writeProduct opts pa mv 0 lenProduct tj tjl p
638+ writeProduct opts targs mv 0 lenProduct p
633 return mv
639 return mv
635 lenProduct = (unTagged2 :: Tagged2 (a :*: b) Int -> Int)
641 lenProduct = (unTagged2 :: Tagged2 (a :*: b) Int -> Int)
@@ -641,15 +647,15 @@ instance ( AllNullary (a :+: b) allNullary
641 -- If all constructors of a sum datatype are nullary and the
647 -- If all constructors of a sum datatype are nullary and the
642 -- 'allNullaryToStringTag' option is set they are encoded to
648 -- 'allNullaryToStringTag' option is set they are encoded to
643 -- strings. This distinction is made by 'sumToJSON':
649 -- strings. This distinction is made by 'sumToJSON':
644− gToJSON opts pa tj tjl = (unTagged :: Tagged allNullary Value -> Value)
650+ gToJSON opts targs = (unTagged :: Tagged allNullary Value -> Value)
645− . sumToJSON opts pa tj tjl
651+ . sumToJSON opts targs
647instance (ToJSON1 f, GToJSON One g) => GToJSON One (f :.: g) where
653instance (ToJSON1 f, GToJSON One g) => GToJSON One (f :.: g) where
648 -- If an occurrence of the last type parameter is nested inside two
654 -- If an occurrence of the last type parameter is nested inside two
649 -- composed types, it is encoded by using the outermost type's ToJSON1
655 -- composed types, it is encoded by using the outermost type's ToJSON1
650 -- instance to generically encode the innermost type:
656 -- instance to generically encode the innermost type:
651− gToJSON opts pa tj tjl =
657+ gToJSON opts targs =
652− let gtj = gToJSON opts pa tj tjl in
658+ let gtj = gToJSON opts targs in
653 liftToJSON gtj (listValue gtj) . unComp1
659 liftToJSON gtj (listValue gtj) . unComp1
655--------------------------------------------------------------------------------
661--------------------------------------------------------------------------------
@@ -657,30 +663,30 @@ instance (ToJSON1 f, GToJSON One g) => GToJSON One (f :.: g) where
658instance OVERLAPPABLE_ (GToEncoding arity a) => GToEncoding arity (M1 i c a) where
664instance OVERLAPPABLE_ (GToEncoding arity a) => GToEncoding arity (M1 i c a) where
659 -- Meta-information, which is not handled elsewhere, is ignored:
665 -- Meta-information, which is not handled elsewhere, is ignored:
660− gToEncoding opts pa te tel = gToEncoding opts pa te tel . unM1
666+ gToEncoding opts targs = gToEncoding opts targs . unM1
662instance (ToJSON a) => GToEncoding arity (K1 i a) where
668instance (ToJSON a) => GToEncoding arity (K1 i a) where
663 -- Constant values are encoded using their ToJSON instance:
669 -- Constant values are encoded using their ToJSON instance:
664− gToEncoding _opts _ _ _ = toEncoding . unK1
670+ gToEncoding _opts _ = toEncoding . unK1
666instance GToEncoding One Par1 where
672instance GToEncoding One Par1 where
667 -- Direct occurrences of the last type parameter are encoded with the
673 -- Direct occurrences of the last type parameter are encoded with the
668 -- function passed in as an argument:
674 -- function passed in as an argument:
669− gToEncoding _opts _ te _ = te . unPar1
675+ gToEncoding _opts (To1Args te _) = te . unPar1
671instance (ToJSON1 f) => GToEncoding One (Rec1 f) where
677instance (ToJSON1 f) => GToEncoding One (Rec1 f) where
672 -- Recursive occurrences of the last type parameter are encoded using their
678 -- Recursive occurrences of the last type parameter are encoded using their
673 -- ToEncoding1 instance:
679 -- ToEncoding1 instance:
674− gToEncoding _opts _ te tel = liftToEncoding te tel . unRec1
680+ gToEncoding _opts (To1Args te tel) = liftToEncoding te tel . unRec1
676instance GToEncoding arity U1 where
682instance GToEncoding arity U1 where
677 -- Empty constructors are encoded to an empty array:
683 -- Empty constructors are encoded to an empty array:
678− gToEncoding _opts _ _ _ _ = E.emptyArray_
684+ gToEncoding _opts _ _ = E.emptyArray_
680instance (ConsToEncoding arity a) => GToEncoding arity (C1 c a) where
686instance (ConsToEncoding arity a) => GToEncoding arity (C1 c a) where
681 -- Constructors need to be encoded differently depending on whether they're
687 -- Constructors need to be encoded differently depending on whether they're
682 -- a record or not. This distinction is made by 'consToEncoding':
688 -- a record or not. This distinction is made by 'consToEncoding':
683− gToEncoding opts pa te tel = consToEncoding opts pa te tel . unM1
689+ gToEncoding opts targs = consToEncoding opts targs . unM1
685instance ( EncodeProduct arity a
691instance ( EncodeProduct arity a
686 , EncodeProduct arity b
692 , EncodeProduct arity b
@@ -688,7 +694,7 @@ instance ( EncodeProduct arity a
688 -- Products are encoded to an array. Here we allocate a mutable vector of
694 -- Products are encoded to an array. Here we allocate a mutable vector of
689 -- the same size as the product and write the product's elements to it using
695 -- the same size as the product and write the product's elements to it using
690 -- 'encodeProduct':
696 -- 'encodeProduct':
691− gToEncoding opts pa te tel p = E.tuple $ encodeProduct opts pa te tel p
697+ gToEncoding opts targs p = E.tuple $ encodeProduct opts targs p
693instance ( AllNullary (a :+: b) allNullary
699instance ( AllNullary (a :+: b) allNullary
694 , SumToEncoding arity (a :+: b) allNullary
700 , SumToEncoding arity (a :+: b) allNullary
@@ -696,23 +702,22 @@ instance ( AllNullary (a :+: b) allNullary
696 -- If all constructors of a sum datatype are nullary and the
702 -- If all constructors of a sum datatype are nullary and the
697 -- 'allNullaryToStringTag' option is set they are encoded to
703 -- 'allNullaryToStringTag' option is set they are encoded to
698 -- strings. This distinction is made by 'sumToEncoding':
704 -- strings. This distinction is made by 'sumToEncoding':
699− gToEncoding opts pa te tel
705+ gToEncoding opts targs
700 = (unTagged :: Tagged allNullary Encoding -> Encoding)
706 = (unTagged :: Tagged allNullary Encoding -> Encoding)
701− . sumToEncoding opts pa te tel
707+ . sumToEncoding opts targs
703instance (ToJSON1 f, GToEncoding One g) => GToEncoding One (f :.: g) where
709instance (ToJSON1 f, GToEncoding One g) => GToEncoding One (f :.: g) where
704 -- If an occurrence of the last type parameter is nested inside two
710 -- If an occurrence of the last type parameter is nested inside two
705 -- composed types, it is encoded by using the outermost type's ToJSON1
711 -- composed types, it is encoded by using the outermost type's ToJSON1
706 -- instance to generically encode the innermost type:
712 -- instance to generically encode the innermost type:
707− gToEncoding opts pa te tel =
713+ gToEncoding opts targs =
708− let gte = gToEncoding opts pa te tel in
714+ let gte = gToEncoding opts targs in
709 liftToEncoding gte (listEncoding gte) . unComp1
715 liftToEncoding gte (listEncoding gte) . unComp1
711--------------------------------------------------------------------------------
717--------------------------------------------------------------------------------
713class SumToJSON arity f allNullary where
719class SumToJSON arity f allNullary where
714− sumToJSON :: Options -> Proxy arity
720+ sumToJSON :: Options -> ToArgs Value arity a
715− -> (a -> Value) -> ([a] -> Value)
716 -> f a -> Tagged allNullary Value
721 -> f a -> Tagged allNullary Value
718instance ( GetConName f
723instance ( GetConName f
@@ -720,35 +725,33 @@ instance ( GetConName f
720 , ObjectWithSingleFieldObj arity f
725 , ObjectWithSingleFieldObj arity f
721 , TwoElemArrayObj arity f
726 , TwoElemArrayObj arity f
722 ) => SumToJSON arity f True where
727 ) => SumToJSON arity f True where
723− sumToJSON opts pa tj tjl
728+ sumToJSON opts targs
724 | allNullaryToStringTag opts = Tagged . String . pack
729 | allNullaryToStringTag opts = Tagged . String . pack
725 . constructorTagModifier opts . getConName
730 . constructorTagModifier opts . getConName
726− | otherwise = Tagged . nonAllNullarySumToJSON opts pa tj tjl
731+ | otherwise = Tagged . nonAllNullarySumToJSON opts targs
728instance ( TwoElemArrayObj arity f
733instance ( TwoElemArrayObj arity f
729 , TaggedObjectPairs arity f
734 , TaggedObjectPairs arity f
730 , ObjectWithSingleFieldObj arity f
735 , ObjectWithSingleFieldObj arity f
731 ) => SumToJSON arity f False where
736 ) => SumToJSON arity f False where
732− sumToJSON opts pa tj tjl = Tagged . nonAllNullarySumToJSON opts pa tj tjl
737+ sumToJSON opts targs = Tagged . nonAllNullarySumToJSON opts targs
734nonAllNullarySumToJSON :: ( TwoElemArrayObj arity f
739nonAllNullarySumToJSON :: ( TwoElemArrayObj arity f
735 , TaggedObjectPairs arity f
740 , TaggedObjectPairs arity f
736 , ObjectWithSingleFieldObj arity f
741 , ObjectWithSingleFieldObj arity f
737− ) => Options -> Proxy arity
742+ ) => Options -> ToArgs Value arity a
738− -> (a -> Value) -> ([a] -> Value)
739 -> f a -> Value
743 -> f a -> Value
740−nonAllNullarySumToJSON opts pa tj tjl =
744+nonAllNullarySumToJSON opts targs =
741 case sumEncoding opts of
745 case sumEncoding opts of
742 TaggedObject{..} ->
746 TaggedObject{..} ->
743− object . taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl
747+ object . taggedObjectPairs opts targs tagFieldName contentsFieldName
744− ObjectWithSingleField -> Object . objectWithSingleFieldObj opts pa tj tjl
748+ ObjectWithSingleField -> Object . objectWithSingleFieldObj opts targs
745− TwoElemArray -> Array . twoElemArrayObj opts pa tj tjl
749+ TwoElemArray -> Array . twoElemArrayObj opts targs
747--------------------------------------------------------------------------------
751--------------------------------------------------------------------------------
749class SumToEncoding arity f allNullary where
753class SumToEncoding arity f allNullary where
750− sumToEncoding :: Options -> Proxy arity
754+ sumToEncoding :: Options -> ToArgs Encoding arity a
751− -> (a -> Encoding) -> ([a] -> Encoding)
752 -> f a -> Tagged allNullary Encoding
755 -> f a -> Tagged allNullary Encoding
754instance ( GetConName f
757instance ( GetConName f
@@ -756,116 +759,111 @@ instance ( GetConName f
756 , ObjectWithSingleFieldEnc arity f
759 , ObjectWithSingleFieldEnc arity f
757 , TwoElemArrayEnc arity f
760 , TwoElemArrayEnc arity f
758 ) => SumToEncoding arity f True where
761 ) => SumToEncoding arity f True where
759− sumToEncoding opts pa te tel
762+ sumToEncoding opts targs
760 | allNullaryToStringTag opts = Tagged . toEncoding .
763 | allNullaryToStringTag opts = Tagged . toEncoding .
761 constructorTagModifier opts . getConName
764 constructorTagModifier opts . getConName
762− | otherwise = Tagged . nonAllNullarySumToEncoding opts pa te tel
765+ | otherwise = Tagged . nonAllNullarySumToEncoding opts targs
764instance ( TwoElemArrayEnc arity f
767instance ( TwoElemArrayEnc arity f
765 , TaggedObjectEnc arity f
768 , TaggedObjectEnc arity f
766 , ObjectWithSingleFieldEnc arity f
769 , ObjectWithSingleFieldEnc arity f
767 ) => SumToEncoding arity f False where
770 ) => SumToEncoding arity f False where
768− sumToEncoding opts pa te tel = Tagged . nonAllNullarySumToEncoding opts pa te tel
771+ sumToEncoding opts targs = Tagged . nonAllNullarySumToEncoding opts targs
770nonAllNullarySumToEncoding :: ( TwoElemArrayEnc arity f
773nonAllNullarySumToEncoding :: ( TwoElemArrayEnc arity f
771 , TaggedObjectEnc arity f
774 , TaggedObjectEnc arity f
772 , ObjectWithSingleFieldEnc arity f
775 , ObjectWithSingleFieldEnc arity f
773− ) => Options -> Proxy arity
776+ ) => Options -> ToArgs Encoding arity a
774− -> (a -> Encoding) -> ([a] -> Encoding)
775 -> f a -> Encoding
777 -> f a -> Encoding
776−nonAllNullarySumToEncoding opts pa te tel =
778+nonAllNullarySumToEncoding opts targs =
777 case sumEncoding opts of
779 case sumEncoding opts of
778 TaggedObject{..} ->
780 TaggedObject{..} ->
779− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel
781+ taggedObjectEnc opts targs tagFieldName contentsFieldName
780− ObjectWithSingleField -> objectWithSingleFieldEnc opts pa te tel
782+ ObjectWithSingleField -> objectWithSingleFieldEnc opts targs
781− TwoElemArray -> twoElemArrayEnc opts pa te tel
783+ TwoElemArray -> twoElemArrayEnc opts targs
783--------------------------------------------------------------------------------
785--------------------------------------------------------------------------------
785class TaggedObjectPairs arity f where
787class TaggedObjectPairs arity f where
786− taggedObjectPairs :: Options -> Proxy arity
788+ taggedObjectPairs :: Options -> ToArgs Value arity a
787 -> String -> String
789 -> String -> String
788− -> (a -> Value) -> ([a] -> Value)
789 -> f a -> [Pair]
790 -> f a -> [Pair]
791instance ( TaggedObjectPairs arity a
792instance ( TaggedObjectPairs arity a
792 , TaggedObjectPairs arity b
793 , TaggedObjectPairs arity b
793 ) => TaggedObjectPairs arity (a :+: b) where
794 ) => TaggedObjectPairs arity (a :+: b) where
794− taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl (L1 x) =
795+ taggedObjectPairs opts targs tagFieldName contentsFieldName (L1 x) =
795− taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl x
796+ taggedObjectPairs opts targs tagFieldName contentsFieldName x
796− taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl (R1 x) =
797+ taggedObjectPairs opts targs tagFieldName contentsFieldName (R1 x) =
797− taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl x
798+ taggedObjectPairs opts targs tagFieldName contentsFieldName x
799instance ( IsRecord a isRecord
800instance ( IsRecord a isRecord
800 , TaggedObjectPairs' arity a isRecord
801 , TaggedObjectPairs' arity a isRecord
801 , Constructor c
802 , Constructor c
802 ) => TaggedObjectPairs arity (C1 c a) where
803 ) => TaggedObjectPairs arity (C1 c a) where
803− taggedObjectPairs opts pa tagFieldName contentsFieldName tj tjl =
804+ taggedObjectPairs opts targs tagFieldName contentsFieldName =
804 (pack tagFieldName .= constructorTagModifier opts
805 (pack tagFieldName .= constructorTagModifier opts
805 (conName (undefined :: t c a p)) :) .
806 (conName (undefined :: t c a p)) :) .
806 (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
807 (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
807− taggedObjectPairs' opts pa contentsFieldName tj tjl . unM1
808+ taggedObjectPairs' opts targs contentsFieldName . unM1
809class TaggedObjectPairs' arity f isRecord where
810class TaggedObjectPairs' arity f isRecord where
810− taggedObjectPairs' :: Options -> Proxy arity
811+ taggedObjectPairs' :: Options -> ToArgs Value arity a
811− -> String -> (a -> Value) -> ([a] -> Value)
812− -> f a -> Tagged isRecord [Pair]
812+ -> String -> f a -> Tagged isRecord [Pair]
814instance OVERLAPPING_ TaggedObjectPairs' arity U1 False where
814instance OVERLAPPING_ TaggedObjectPairs' arity U1 False where
815− taggedObjectPairs' _ _ _ _ _ _ = Tagged []
815+ taggedObjectPairs' _ _ _ _ = Tagged []
817instance (RecordToPairs arity f) => TaggedObjectPairs' arity f True where
817instance (RecordToPairs arity f) => TaggedObjectPairs' arity f True where
818− taggedObjectPairs' opts pa _ tj tjl =
818+ taggedObjectPairs' opts targs _ =
819− Tagged . toList . recordToPairs opts pa tj tjl
819+ Tagged . toList . recordToPairs opts targs
821instance (GToJSON arity f) => TaggedObjectPairs' arity f False where
821instance (GToJSON arity f) => TaggedObjectPairs' arity f False where
822− taggedObjectPairs' opts pa contentsFieldName tj tjl =
822+ taggedObjectPairs' opts targs contentsFieldName =
823− Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts pa tj tjl
823+ Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts targs
825--------------------------------------------------------------------------------
825--------------------------------------------------------------------------------
827class TaggedObjectEnc arity f where
827class TaggedObjectEnc arity f where
828− taggedObjectEnc :: Options -> Proxy arity
828+ taggedObjectEnc :: Options -> ToArgs Encoding arity a
829 -> String -> String
829 -> String -> String
830− -> (a -> Encoding) -> ([a] -> Encoding)
831 -> f a -> Encoding
830 -> f a -> Encoding
833instance ( TaggedObjectEnc arity a
832instance ( TaggedObjectEnc arity a
834 , TaggedObjectEnc arity b
833 , TaggedObjectEnc arity b
835 ) => TaggedObjectEnc arity (a :+: b) where
834 ) => TaggedObjectEnc arity (a :+: b) where
836− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel (L1 x) =
835+ taggedObjectEnc opts targs tagFieldName contentsFieldName (L1 x) =
837− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel x
836+ taggedObjectEnc opts targs tagFieldName contentsFieldName x
838− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel (R1 x) =
837+ taggedObjectEnc opts targs tagFieldName contentsFieldName (R1 x) =
839− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel x
838+ taggedObjectEnc opts targs tagFieldName contentsFieldName x
841instance ( IsRecord a isRecord
840instance ( IsRecord a isRecord
842 , TaggedObjectEnc' arity a isRecord
841 , TaggedObjectEnc' arity a isRecord
843 , Constructor c
842 , Constructor c
844 ) => TaggedObjectEnc arity (C1 c a) where
843 ) => TaggedObjectEnc arity (C1 c a) where
845− taggedObjectEnc opts pa tagFieldName contentsFieldName te tel v =
844+ taggedObjectEnc opts targs tagFieldName contentsFieldName v =
846 E.wrapObject $
845 E.wrapObject $
847 (E.string tagFieldName ><
846 (E.string tagFieldName ><
848 E.colon ><
847 E.colon ><
849 toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))) ><
848 toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))) ><
850 ((unTagged :: Tagged isRecord Encoding -> Encoding) .
849 ((unTagged :: Tagged isRecord Encoding -> Encoding) .
851− taggedObjectEnc' opts pa contentsFieldName te tel . unM1 $ v)
850+ taggedObjectEnc' opts targs contentsFieldName . unM1 $ v)
853class TaggedObjectEnc' arity f isRecord where
852class TaggedObjectEnc' arity f isRecord where
854− taggedObjectEnc' :: Options -> Proxy arity
853+ taggedObjectEnc' :: Options -> ToArgs Encoding arity a
855− -> String -> (a -> Encoding) -> ([a] -> Encoding)
856− -> f a -> Tagged isRecord Encoding
854+ -> String -> f a -> Tagged isRecord Encoding
858instance OVERLAPPING_ TaggedObjectEnc' arity U1 False where
856instance OVERLAPPING_ TaggedObjectEnc' arity U1 False where
859− taggedObjectEnc' _ _ _ _ _ _ = Tagged E.empty
857+ taggedObjectEnc' _ _ _ _ = Tagged E.empty
861instance (RecordToEncoding arity f) => TaggedObjectEnc' arity f True where
859instance (RecordToEncoding arity f) => TaggedObjectEnc' arity f True where
862− taggedObjectEnc' opts pa _ te tel = Tagged . (E.comma ><) . fst
860+ taggedObjectEnc' opts targs _ = Tagged . (E.comma ><) . fst
863− . recordToEncoding opts pa te tel
861+ . recordToEncoding opts targs
865instance (GToEncoding arity f) => TaggedObjectEnc' arity f False where
863instance (GToEncoding arity f) => TaggedObjectEnc' arity f False where
866− taggedObjectEnc' opts pa contentsFieldName te tel =
864+ taggedObjectEnc' opts targs contentsFieldName =
867 Tagged . (\z -> E.comma >< toEncoding contentsFieldName >< E.colon >< z) .
865 Tagged . (\z -> E.comma >< toEncoding contentsFieldName >< E.colon >< z) .
868− gToEncoding opts pa te tel
866+ gToEncoding opts targs
870--------------------------------------------------------------------------------
868--------------------------------------------------------------------------------
@@ -883,137 +881,129 @@ instance (Constructor c) => GetConName (C1 c a) where
883--------------------------------------------------------------------------------
881--------------------------------------------------------------------------------
885class TwoElemArrayObj arity f where
883class TwoElemArrayObj arity f where
886− twoElemArrayObj :: Options -> Proxy arity
884+ twoElemArrayObj :: Options -> ToArgs Value arity a
887− -> (a -> Value) -> ([a] -> Value)
888 -> f a -> V.Vector Value
885 -> f a -> V.Vector Value
890instance ( TwoElemArrayObj arity a
887instance ( TwoElemArrayObj arity a
891 , TwoElemArrayObj arity b
888 , TwoElemArrayObj arity b
892 ) => TwoElemArrayObj arity (a :+: b) where
889 ) => TwoElemArrayObj arity (a :+: b) where
893− twoElemArrayObj opts pa tj tjl (L1 x) = twoElemArrayObj opts pa tj tjl x
890+ twoElemArrayObj opts targs (L1 x) = twoElemArrayObj opts targs x
894− twoElemArrayObj opts pa tj tjl (R1 x) = twoElemArrayObj opts pa tj tjl x
891+ twoElemArrayObj opts targs (R1 x) = twoElemArrayObj opts targs x
896instance ( GToJSON arity a
893instance ( GToJSON arity a
897 , ConsToJSON arity a
894 , ConsToJSON arity a
898 , Constructor c
895 , Constructor c
899 ) => TwoElemArrayObj arity (C1 c a) where
896 ) => TwoElemArrayObj arity (C1 c a) where
900− twoElemArrayObj opts pa tj tjl x = V.create $ do
897+ twoElemArrayObj opts targs x = V.create $ do
901 mv <- VM.unsafeNew 2
898 mv <- VM.unsafeNew 2
902 VM.unsafeWrite mv 0 $ String $ pack $ constructorTagModifier opts
899 VM.unsafeWrite mv 0 $ String $ pack $ constructorTagModifier opts
903 $ conName (undefined :: t c a p)
900 $ conName (undefined :: t c a p)
904− VM.unsafeWrite mv 1 $ gToJSON opts pa tj tjl x
901+ VM.unsafeWrite mv 1 $ gToJSON opts targs x
905 return mv
902 return mv
907--------------------------------------------------------------------------------
904--------------------------------------------------------------------------------
909class TwoElemArrayEnc arity f where
906class TwoElemArrayEnc arity f where
910− twoElemArrayEnc :: Options -> Proxy arity
907+ twoElemArrayEnc :: Options -> ToArgs Encoding arity a
911− -> (a -> Encoding) -> ([a] -> Encoding)
912 -> f a -> Encoding
908 -> f a -> Encoding
914instance ( TwoElemArrayEnc arity a
910instance ( TwoElemArrayEnc arity a
915 , TwoElemArrayEnc arity b
911 , TwoElemArrayEnc arity b
916 ) => TwoElemArrayEnc arity (a :+: b) where
912 ) => TwoElemArrayEnc arity (a :+: b) where
917− twoElemArrayEnc opts pa te tel (L1 x) = twoElemArrayEnc opts pa te tel x
913+ twoElemArrayEnc opts targs (L1 x) = twoElemArrayEnc opts targs x
918− twoElemArrayEnc opts pa te tel (R1 x) = twoElemArrayEnc opts pa te tel x
914+ twoElemArrayEnc opts targs (R1 x) = twoElemArrayEnc opts targs x
920instance ( GToEncoding arity a
916instance ( GToEncoding arity a
921 , ConsToEncoding arity a
917 , ConsToEncoding arity a
922 , Constructor c
918 , Constructor c
923 ) => TwoElemArrayEnc arity (C1 c a) where
919 ) => TwoElemArrayEnc arity (C1 c a) where
924− twoElemArrayEnc opts pa te tel x = E.tuple $
920+ twoElemArrayEnc opts targs x = E.tuple $
925 toEncoding (constructorTagModifier opts (conName (undefined :: t c a p))) >*<
921 toEncoding (constructorTagModifier opts (conName (undefined :: t c a p))) >*<
926− gToEncoding opts pa te tel x
922+ gToEncoding opts targs x
928--------------------------------------------------------------------------------
924--------------------------------------------------------------------------------
930class ConsToJSON arity f where
926class ConsToJSON arity f where
931− consToJSON :: Options -> Proxy arity
927+ consToJSON :: Options -> ToArgs Value arity a
932− -> (a -> Value) -> ([a] -> Value)
933 -> f a -> Value
928 -> f a -> Value
935class ConsToJSON' arity f isRecord where
930class ConsToJSON' arity f isRecord where
936− consToJSON' :: Options -> Proxy arity
931+ consToJSON' :: Options -> ToArgs Value arity a
937 -> Bool -- ^ Are we a record with one field?
932 -> Bool -- ^ Are we a record with one field?
938− -> (a -> Value) -> ([a] -> Value)
939 -> f a -> Tagged isRecord Value
933 -> f a -> Tagged isRecord Value
941instance ( IsRecord f isRecord
935instance ( IsRecord f isRecord
942 , ConsToJSON' arity f isRecord
936 , ConsToJSON' arity f isRecord
943 ) => ConsToJSON arity f where
937 ) => ConsToJSON arity f where
944− consToJSON opts pa tj tjl =
938+ consToJSON opts targs =
945 (unTagged :: Tagged isRecord Value -> Value)
939 (unTagged :: Tagged isRecord Value -> Value)
946− . consToJSON' opts pa (isUnary (undefined :: f a)) tj tjl
940+ . consToJSON' opts targs (isUnary (undefined :: f a))
948instance (RecordToPairs arity f) => ConsToJSON' arity f True where
942instance (RecordToPairs arity f) => ConsToJSON' arity f True where
949− consToJSON' opts pa isUn tj tjl f = let
943+ consToJSON' opts targs isUn f = let
950− vals = toList $ recordToPairs opts pa tj tjl f
944+ vals = toList $ recordToPairs opts targs f
951 in case (unwrapUnaryRecords opts,isUn,vals) of
945 in case (unwrapUnaryRecords opts,isUn,vals) of
952 (True,True,[(_,val)]) -> Tagged val
946 (True,True,[(_,val)]) -> Tagged val
953 _ -> Tagged $ object vals
947 _ -> Tagged $ object vals
955instance GToJSON arity f => ConsToJSON' arity f False where
949instance GToJSON arity f => ConsToJSON' arity f False where
956− consToJSON' opts pa _ tj tjl = Tagged . gToJSON opts pa tj tjl
950+ consToJSON' opts targs _ = Tagged . gToJSON opts targs
958--------------------------------------------------------------------------------
952--------------------------------------------------------------------------------
960class ConsToEncoding arity f where
954class ConsToEncoding arity f where
961− consToEncoding :: Options -> Proxy arity
955+ consToEncoding :: Options -> ToArgs Encoding arity a
962− -> (a -> Encoding) -> ([a] -> Encoding)
963 -> f a -> Encoding
956 -> f a -> Encoding
965class ConsToEncoding' arity f isRecord where
958class ConsToEncoding' arity f isRecord where
966− consToEncoding' :: Options -> Proxy arity
959+ consToEncoding' :: Options -> ToArgs Encoding arity a
967 -> Bool -- ^ Are we a record with one field?
960 -> Bool -- ^ Are we a record with one field?
968− -> (a -> Encoding) -> ([a] -> Encoding)
969 -> f a -> Tagged isRecord Encoding
961 -> f a -> Tagged isRecord Encoding
971instance ( IsRecord f isRecord
963instance ( IsRecord f isRecord
972 , ConsToEncoding' arity f isRecord
964 , ConsToEncoding' arity f isRecord
973 ) => ConsToEncoding arity f where
965 ) => ConsToEncoding arity f where
974− consToEncoding opts pa te tel =
966+ consToEncoding opts targs =
975 (unTagged :: Tagged isRecord Encoding -> Encoding)
967 (unTagged :: Tagged isRecord Encoding -> Encoding)
976− . consToEncoding' opts pa (isUnary (undefined :: f a)) te tel
968+ . consToEncoding' opts targs (isUnary (undefined :: f a))
978instance (RecordToEncoding arity f) => ConsToEncoding' arity f True where
970instance (RecordToEncoding arity f) => ConsToEncoding' arity f True where
979− consToEncoding' opts pa isUn te tel x =
971+ consToEncoding' opts targs isUn x =
980− let (enc, mbVal) = recordToEncoding opts pa te tel x
972+ let (enc, mbVal) = recordToEncoding opts targs x
981 in case (unwrapUnaryRecords opts, isUn, mbVal) of
973 in case (unwrapUnaryRecords opts, isUn, mbVal) of
982 (True, True, Just val) -> Tagged val
974 (True, True, Just val) -> Tagged val
983 _ -> Tagged $ E.wrapObject enc
975 _ -> Tagged $ E.wrapObject enc
985instance GToEncoding arity f => ConsToEncoding' arity f False where
977instance GToEncoding arity f => ConsToEncoding' arity f False where
986− consToEncoding' opts pa _ te tel = Tagged . gToEncoding opts pa te tel
978+ consToEncoding' opts targs _ = Tagged . gToEncoding opts targs
988--------------------------------------------------------------------------------
980--------------------------------------------------------------------------------
990class RecordToPairs arity f where
982class RecordToPairs arity f where
991− recordToPairs :: Options -> Proxy arity
983+ recordToPairs :: Options -> ToArgs Value arity a
992− -> (a -> Value) -> ([a] -> Value)
993 -> f a -> DList Pair
984 -> f a -> DList Pair
995instance ( RecordToPairs arity a
986instance ( RecordToPairs arity a
996 , RecordToPairs arity b
987 , RecordToPairs arity b
997 ) => RecordToPairs arity (a :*: b) where
988 ) => RecordToPairs arity (a :*: b) where
998− recordToPairs opts pa tj tjl (a :*: b) = recordToPairs opts pa tj tjl a <>
989+ recordToPairs opts targs (a :*: b) = recordToPairs opts targs a <>
999− recordToPairs opts pa tj tjl b
990+ recordToPairs opts targs b
1001instance (Selector s, GToJSON arity a) => RecordToPairs arity (S1 s a) where
992instance (Selector s, GToJSON arity a) => RecordToPairs arity (S1 s a) where
1002 recordToPairs = fieldToPair
993 recordToPairs = fieldToPair
1004instance OVERLAPPING_ (Selector s, ToJSON a) =>
995instance OVERLAPPING_ (Selector s, ToJSON a) =>
1005 RecordToPairs arity (S1 s (K1 i (Maybe a))) where
996 RecordToPairs arity (S1 s (K1 i (Maybe a))) where
1006− recordToPairs opts _ _ _ (M1 k1) | omitNothingFields opts
997+ recordToPairs opts _ (M1 k1) | omitNothingFields opts
1007− , K1 Nothing <- k1 = DList.empty
998+ , K1 Nothing <- k1 = DList.empty
1008− recordToPairs opts pa tj tjl m1 = fieldToPair opts pa tj tjl m1
999+ recordToPairs opts targs m1 = fieldToPair opts targs m1
1010fieldToPair :: (Selector s, GToJSON arity a)
1001fieldToPair :: (Selector s, GToJSON arity a)
1011− => Options -> Proxy arity
1002+ => Options -> ToArgs Value arity p
1012− -> (p -> Value) -> ([p] -> Value)
1013 -> S1 s a p -> DList Pair
1003 -> S1 s a p -> DList Pair
1014−fieldToPair opts pa tj tjl m1 = pure ( pack $ fieldLabelModifier opts $ selName m1
1004+fieldToPair opts targs m1 = pure ( pack $ fieldLabelModifier opts $ selName m1
1015− , gToJSON opts pa tj tjl (unM1 m1)
1005+ , gToJSON opts targs (unM1 m1)
1018--------------------------------------------------------------------------------
1008--------------------------------------------------------------------------------
@@ -1021,22 +1011,21 @@ class RecordToEncoding arity f where
1021 -- 1st element: whole thing
1011 -- 1st element: whole thing
1022 -- 2nd element: in case the record has only 1 field, just the value
1012 -- 2nd element: in case the record has only 1 field, just the value
1023 -- of the field (without the key); 'Nothing' otherwise
1013 -- of the field (without the key); 'Nothing' otherwise
1024− recordToEncoding :: Options -> Proxy arity
1014+ recordToEncoding :: Options -> ToArgs Encoding arity a
1025− -> (a -> Encoding) -> ([a] -> Encoding)
1026 -> f a -> (Encoding, Maybe Encoding)
1015 -> f a -> (Encoding, Maybe Encoding)
1028instance ( RecordToEncoding arity a
1017instance ( RecordToEncoding arity a
1029 , RecordToEncoding arity b
1018 , RecordToEncoding arity b
1030 ) => RecordToEncoding arity (a :*: b) where
1019 ) => RecordToEncoding arity (a :*: b) where
1031− recordToEncoding opts pa te tel (a :*: b) | omitNothingFields opts =
1020+ recordToEncoding opts targs (a :*: b) | omitNothingFields opts =
1032 (E.econcat $ intersperse E.comma $
1021 (E.econcat $ intersperse E.comma $
1033 filter (not . E.nullEncoding)
1022 filter (not . E.nullEncoding)
1034− [ fst (recordToEncoding opts pa te tel a)
1023+ [ fst (recordToEncoding opts targs a)
1035− , fst (recordToEncoding opts pa te tel b) ]
1024+ , fst (recordToEncoding opts targs b) ]
1036 , Nothing)
1025 , Nothing)
1037− recordToEncoding opts pa te tel (a :*: b) =
1026+ recordToEncoding opts targs (a :*: b) =
1038− (fst (recordToEncoding opts pa te tel a) >< E.comma ><
1027+ (fst (recordToEncoding opts targs a) >< E.comma ><
1039− fst (recordToEncoding opts pa te tel b),
1028+ fst (recordToEncoding opts targs b),
1040 Nothing)
1029 Nothing)
@@ -1045,87 +1034,82 @@ instance (Selector s, GToEncoding arity a) => RecordToEncoding arity (S1 s a) wh
1046instance OVERLAPPING_ (Selector s, ToJSON a) =>
1035instance OVERLAPPING_ (Selector s, ToJSON a) =>
1047 RecordToEncoding arity (S1 s (K1 i (Maybe a))) where
1036 RecordToEncoding arity (S1 s (K1 i (Maybe a))) where
1048− recordToEncoding opts _ _ _ (M1 k1) | omitNothingFields opts
1037+ recordToEncoding opts _ (M1 k1) | omitNothingFields opts
1049− , K1 Nothing <- k1 = (E.empty, Nothing)
1038+ , K1 Nothing <- k1 = (E.empty, Nothing)
1050− recordToEncoding opts pa te tel m1 = fieldToEncoding opts pa te tel m1
1039+ recordToEncoding opts targs m1 = fieldToEncoding opts targs m1
1052fieldToEncoding :: (Selector s, GToEncoding arity a)
1041fieldToEncoding :: (Selector s, GToEncoding arity a)
1053− => Options -> Proxy arity
1042+ => Options -> ToArgs Encoding arity p
1054− -> (p -> Encoding) -> ([p] -> Encoding)
1055 -> S1 s a p -> (Encoding, Maybe Encoding)
1043 -> S1 s a p -> (Encoding, Maybe Encoding)
1056−fieldToEncoding opts pa te tel m1 =
1044+fieldToEncoding opts targs m1 =
1057 let keyBuilder = toEncoding (fieldLabelModifier opts $ selName m1)
1045 let keyBuilder = toEncoding (fieldLabelModifier opts $ selName m1)
1058− valueBuilder = gToEncoding opts pa te tel (unM1 m1)
1046+ valueBuilder = gToEncoding opts targs (unM1 m1)
1059 in (keyBuilder >< E.colon >< valueBuilder, Just valueBuilder)
1047 in (keyBuilder >< E.colon >< valueBuilder, Just valueBuilder)
1061--------------------------------------------------------------------------------
1049--------------------------------------------------------------------------------
1063class WriteProduct arity f where
1051class WriteProduct arity f where
1064 writeProduct :: Options
1052 writeProduct :: Options
1065− -> Proxy arity
1053+ -> ToArgs Value arity a
1066 -> VM.MVector s Value
1054 -> VM.MVector s Value
1067 -> Int -- ^ index
1055 -> Int -- ^ index
1068 -> Int -- ^ length
1056 -> Int -- ^ length
1072 -> ST s ()
1058 -> ST s ()
1074instance ( WriteProduct arity a
1060instance ( WriteProduct arity a
1075 , WriteProduct arity b
1061 , WriteProduct arity b
1076 ) => WriteProduct arity (a :*: b) where
1062 ) => WriteProduct arity (a :*: b) where
1077− writeProduct opts pa mv ix len tj tjl (a :*: b) = do
1063+ writeProduct opts targs mv ix len (a :*: b) = do
1078− writeProduct opts pa mv ix lenL tj tjl a
1064+ writeProduct opts targs mv ix lenL a
1079− writeProduct opts pa mv ixR lenR tj tjl b
1065+ writeProduct opts targs mv ixR lenR b
1081 lenL = len `unsafeShiftR` 1
1067 lenL = len `unsafeShiftR` 1
1082 lenR = len - lenL
1068 lenR = len - lenL
1083 ixR = ix + lenL
1069 ixR = ix + lenL
1085instance OVERLAPPABLE_ (GToJSON arity a) => WriteProduct arity a where
1071instance OVERLAPPABLE_ (GToJSON arity a) => WriteProduct arity a where
1086− writeProduct opts pa mv ix _ tj tjl =
1072+ writeProduct opts targs mv ix _ =
1087− VM.unsafeWrite mv ix . gToJSON opts pa tj tjl
1073+ VM.unsafeWrite mv ix . gToJSON opts targs
1089--------------------------------------------------------------------------------
1075--------------------------------------------------------------------------------
1091class EncodeProduct arity f where
1077class EncodeProduct arity f where
1092− encodeProduct :: Options -> Proxy arity
1078+ encodeProduct :: Options -> ToArgs Encoding arity a
1093− -> (a -> Encoding) -> ([a] -> Encoding)
1094 -> f a -> Encoding' E.InArray
1079 -> f a -> Encoding' E.InArray
1096instance ( EncodeProduct arity a
1081instance ( EncodeProduct arity a
1097 , EncodeProduct arity b
1082 , EncodeProduct arity b
1098 ) => EncodeProduct arity (a :*: b) where
1083 ) => EncodeProduct arity (a :*: b) where
1099− encodeProduct opts pa te tel (a :*: b) | omitNothingFields opts =
1084+ encodeProduct opts targs (a :*: b) | omitNothingFields opts =
1100 E.econcat $ intersperse E.comma $
1085 E.econcat $ intersperse E.comma $
1101 filter (not . E.nullEncoding)
1086 filter (not . E.nullEncoding)
1102− [encodeProduct opts pa te tel a, encodeProduct opts pa te tel b]
1087+ [encodeProduct opts targs a, encodeProduct opts targs b]
1103− encodeProduct opts pa te tel (a :*: b) = encodeProduct opts pa te tel a >*<
1088+ encodeProduct opts targs (a :*: b) = encodeProduct opts targs a >*<
1104− encodeProduct opts pa te tel b
1089+ encodeProduct opts targs b
1106instance OVERLAPPABLE_ (GToEncoding arity a) => EncodeProduct arity a where
1091instance OVERLAPPABLE_ (GToEncoding arity a) => EncodeProduct arity a where
1107− encodeProduct opts pa te tel a = E.retagEncoding $ gToEncoding opts pa te tel a
1092+ encodeProduct opts targs a = E.retagEncoding $ gToEncoding opts targs a
1109--------------------------------------------------------------------------------
1094--------------------------------------------------------------------------------
1111class ObjectWithSingleFieldObj arity f where
1096class ObjectWithSingleFieldObj arity f where
1112− objectWithSingleFieldObj :: Options -> Proxy arity
1097+ objectWithSingleFieldObj :: Options -> ToArgs Value arity a
1113− -> (a -> Value) -> ([a] -> Value)
1114 -> f a -> Object
1098 -> f a -> Object
1116instance ( ObjectWithSingleFieldObj arity a
1100instance ( ObjectWithSingleFieldObj arity a
1117 , ObjectWithSingleFieldObj arity b
1101 , ObjectWithSingleFieldObj arity b
1118 ) => ObjectWithSingleFieldObj arity (a :+: b) where
1102 ) => ObjectWithSingleFieldObj arity (a :+: b) where
1119− objectWithSingleFieldObj opts pa tj tjl (L1 x) =
1103+ objectWithSingleFieldObj opts targs (L1 x) =
1120− objectWithSingleFieldObj opts pa tj tjl x
1104+ objectWithSingleFieldObj opts targs x
1121− objectWithSingleFieldObj opts pa tj tjl (R1 x) =
1105+ objectWithSingleFieldObj opts targs (R1 x) =
1122− objectWithSingleFieldObj opts pa tj tjl x
1106+ objectWithSingleFieldObj opts targs x
1124instance ( GToJSON arity a
1108instance ( GToJSON arity a
1125 , ConsToJSON arity a
1109 , ConsToJSON arity a
1126 , Constructor c
1110 , Constructor c
1127 ) => ObjectWithSingleFieldObj arity (C1 c a) where
1111 ) => ObjectWithSingleFieldObj arity (C1 c a) where
1128− objectWithSingleFieldObj opts pa tj tjl = H.singleton typ . gToJSON opts pa tj tjl
1112+ objectWithSingleFieldObj opts targs = H.singleton typ . gToJSON opts targs
1130 typ = pack $ constructorTagModifier opts $
1114 typ = pack $ constructorTagModifier opts $
1131 conName (undefined :: t c a p)
1115 conName (undefined :: t c a p)
@@ -1133,29 +1117,28 @@ instance ( GToJSON arity a
1133--------------------------------------------------------------------------------
1117--------------------------------------------------------------------------------
1135class ObjectWithSingleFieldEnc arity f where
1119class ObjectWithSingleFieldEnc arity f where
1136− objectWithSingleFieldEnc :: Options -> Proxy arity
1120+ objectWithSingleFieldEnc :: Options -> ToArgs Encoding arity a
1137− -> (a -> Encoding) -> ([a] -> Encoding)
1138 -> f a -> Encoding
1121 -> f a -> Encoding
1140instance ( ObjectWithSingleFieldEnc arity a
1123instance ( ObjectWithSingleFieldEnc arity a
1141 , ObjectWithSingleFieldEnc arity b
1124 , ObjectWithSingleFieldEnc arity b
1142 ) => ObjectWithSingleFieldEnc arity (a :+: b) where
1125 ) => ObjectWithSingleFieldEnc arity (a :+: b) where
1143− objectWithSingleFieldEnc opts pa te tel (L1 x) =
1126+ objectWithSingleFieldEnc opts targs (L1 x) =
1144− objectWithSingleFieldEnc opts pa te tel x
1127+ objectWithSingleFieldEnc opts targs x
1145− objectWithSingleFieldEnc opts pa te tel (R1 x) =
1128+ objectWithSingleFieldEnc opts targs (R1 x) =
1146− objectWithSingleFieldEnc opts pa te tel x
1129+ objectWithSingleFieldEnc opts targs x
1148instance ( GToEncoding arity a
1131instance ( GToEncoding arity a
1149 , ConsToEncoding arity a
1132 , ConsToEncoding arity a
1150 , Constructor c
1133 , Constructor c
1151 ) => ObjectWithSingleFieldEnc arity (C1 c a) where
1134 ) => ObjectWithSingleFieldEnc arity (C1 c a) where
1152− objectWithSingleFieldEnc opts pa te tel v =
1135+ objectWithSingleFieldEnc opts targs v =
1153 E.openCurly ><
1136 E.openCurly ><
1154 toEncoding
1137 toEncoding
1155 (constructorTagModifier opts
1138 (constructorTagModifier opts
1156 (conName (undefined :: t c a p))) ><
1139 (conName (undefined :: t c a p))) ><
1157 E.colon ><
1140 E.colon ><
1158− gToEncoding opts pa te tel v ><
1141+ gToEncoding opts targs v ><
1159 E.closeCurly
1142 E.closeCurly
1161-------------------------------------------------------------------------------
1144-------------------------------------------------------------------------------